From a53a022f84b9016321f5dc7ae2e3fe3a750597a2 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 9 Sep 2005 18:48:39 +0000 Subject: [kennykb-numerics-branch] Merge updates from HEAD. --- ChangeLog | 95 +++ doc/FileSystem.3 | 14 +- doc/LinkVar.3 | 97 ++- generic/tcl.h | 1915 ++++++++++++++++++++++++------------------------ generic/tclBasic.c | 1846 +++++++++++++++++++++++----------------------- generic/tclCmdAH.c | 19 +- generic/tclEncoding.c | 6 +- generic/tclIORChan.c | 4 +- generic/tclIOUtil.c | 5 +- generic/tclInt.h | 11 +- generic/tclLink.c | 179 ++++- generic/tclListObj.c | 110 +-- generic/tclObj.c | 4 +- generic/tclResult.c | 4 +- generic/tclStringObj.c | 729 +++++++++++++++++- generic/tclTest.c | 275 ++++++- generic/tclUtf.c | 74 +- generic/tclUtil.c | 11 +- library/tm.tcl | 2 +- tests/eval.test | 25 +- tests/link.test | 136 ++-- tests/tm.test | 4 +- tests/utf.test | 5 +- unix/tclUnixChan.c | 4 +- unix/tclUnixFile.c | 12 +- unix/tclUnixSock.c | 4 +- win/tclWinFile.c | 12 +- 27 files changed, 3541 insertions(+), 2061 deletions(-) diff --git a/ChangeLog b/ChangeLog index aefe20c..8644c62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2005-09-09 Don Porter + + [kennykb-numerics-branch] Merge updates from HEAD. + +2005-09-09 Kevin Kenny + + * generic/tclStringObj.c: Added two missing casts to silence + messages from MSVC6. + +2005-09-09 Don Porter + + * generic/tclInt.h: New internal routine TclObjPrintf() + * generic/tclStringObj.c: is similar to TclFormatObj() but + accepts arguments in non-Tcl_Obj format. + + * generic/tclInt.h: New internal routines TclFormatObj() + * generic/tclStringObj.c: and TclAppendFormattedObjs() to offer + sprintf()-like means to append to Tcl_Obj. Work in progress toward + [RFE 572392]. + + * generic/tclCmdAH.c: Compiler directive NEW_FORMAT when #define'd + directs the [format] command to be implemented in terms of the new + TclAppendFormattedObjs() routine. + +2005-09-08 Donal K. Fellows + + TIP#254 IMPLEMENTATION + + * generic/tclLink.c (LinkTraceProc,ObjValue): Added many new of C var + * generic/tcl.h: to link to, making it + * doc/LinkVar.3: easier to seamlessly + * generic/tclTest.c (TestlinkCmd): couple C code and Tcl + * tests/link.test: scripts in an + application. [Patch 1242844] + +2005-09-07 Don Porter + + * generic/tclUtf.c (Tcl_UniCharToUtf): Corrected handling of negative + * tests/utf.test (utf-1.5): Tcl_UniChar input value. Incorrect + handling was producing byte sequences outside of Tcl's legal internal + encoding. [Bug 1283976]. + +2005-09-06 Donal K. Fellows + + * generic/tclInt.h (List): Added flag to keep track of whether a list + * generic/tclListObj.c: with a string rep is provably canonical. + * generic/tclUtil.c (Tcl_ConcatObj): Do efficient concatenation and + * generic/tclBasic.c (Tcl_EvalObjEx): evaluation when the list is + canonical, and not just when the list is pure. This should make the + "pure list" hacking introduced in 8.3 much more robust. + +2005-09-05 Donal K. Fellows + + * generic/tclObj.c (pendingObjDataKey): Added missing 'static' to stop + symbol from leaking outside the Tcl library. [Bug 1263012] + 2005-09-02 Don Porter [kennykb-numerics-branch] @@ -9,6 +65,30 @@ * generic/tclInt.h: Added TCL_PARSE_SCAN_PREFIXES to the flags * generic/tclStrToD.c: accepted by TclParseNumber. +2005-09-01 Andreas Kupries + + * unix/tclUnixSock.c (InitializeHostName): Synchronized use of + static modifier in declaration and definition of function. + + * unix/tclUnixChan.c (FileTruncateProc): Synchronized use of + static modifier in declaration and definition of function. + + * generic/tclResult.c (ReleaseKeys): Synchronized use of static + modifier in declaration and definition of function. + + * generic/tclListObj.c (NewListIntRep): Synchronized use of static + modifier in declaration and definition of function. + + * generic/tclEncoding.c (InitializeEncodingSearchPath): + Synchronized use of static modifier in declaration and + definition of function. + + * generic/tclEncoding.c (FillEncodingFileMap): Synchronized use of + static modifier in declaration and definition of function. + + * generic/tclIORChan.c (RcNewHandle): Synchronized use of static + modifier in declaration and definition of function. + 2005-09-01 Don Porter [kennykb-numerics-branch] @@ -25,6 +105,15 @@ TCL_PARSE_OCTAL_ONLY, and TCL_PARSE_HEXIDECIMAL_ONLY, to give caller more control over the parsing rules. +2005-08-31 Vince Darley + + * doc/FileSystem.3: + * unix/tclUnixFile.c: + * windows/tclWinFile.c: clarify that Tcl_FSMatchInDirectory may + be called with a NULL interpreter, and fix the code so this is + allowed. Tcl's core itself (tclEncoding.c:FillEncodingFileMap()) + calls this with a NULL interpreter. + 2005-08-30 Don Porter [kennykb-numerics-branch] @@ -42,6 +131,12 @@ the entire double range, accepting as many bignums in the domain as that will allow. +2005-08-29 Andreas Kupries + + * library/tm.tcl (::tcl::tm::roots): Accepted Don Porter's patch + for [Tcl SF Bug 1189657]. Syncs the implementation to the + specification (TIP #189). + 2005-08-29 Don Porter [kennykb-numerics-branch] Merge updates from HEAD. diff --git a/doc/FileSystem.3 b/doc/FileSystem.3 index b770951..21609d5 100644 --- a/doc/FileSystem.3 +++ b/doc/FileSystem.3 @@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: FileSystem.3,v 1.50.2.3 2005/04/10 23:14:41 kennykb Exp $ +'\" RCS: @(#) $Id: FileSystem.3,v 1.50.2.4 2005/09/09 18:48:40 dgp Exp $ '\" .so man.macros .TH Filesystem 3 8.4 Tcl "Tcl Library Procedures" @@ -376,8 +376,9 @@ directory for all files which match a given pattern. The appropriate function for the filesystem to which \fIpathPtr\fR belongs will be called. .PP The return value is a standard Tcl result indicating whether an error -occurred in globbing. Error messages are placed in interp, but good -results are placed in the resultPtr given. +occurred in globbing. Error messages are placed in interp (unless +interp is NULL, which is allowed), but good results are placed in the +resultPtr given. .PP Note that the \fBglob\fR code implements recursive patterns internally, so this function will only ever be passed simple patterns, which can be @@ -1095,9 +1096,10 @@ not, so code should be flexible to both possibilities. .PP The return value is a standard Tcl result indicating whether an error occurred in the matching process. Error messages are placed in -\fIinterp\fR; on a \fBTCL_OK\fR result, results should be added to the -\fIresultPtr\fR object given (which can be assumed to be a valid -unshared Tcl list). The matches added +\fIinterp\fR, unless \fIinterp\fR in NULL in which case no error +message need be generated; on a \fBTCL_OK\fR result, results should be +added to the \fIresultPtr\fR object given (which can be assumed to be a +valid unshared Tcl list). The matches added to \fIresultPtr\fR should include any path prefix given in \fIpathPtr\fR (this usually means they will be absolute path specifications). Note that if no matches are found, that simply leads to an empty diff --git a/doc/LinkVar.3 b/doc/LinkVar.3 index 1d6c529..c3a6c2a 100644 --- a/doc/LinkVar.3 +++ b/doc/LinkVar.3 @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: LinkVar.3,v 1.9.2.1 2005/04/10 23:14:41 kennykb Exp $ +'\" RCS: @(#) $Id: LinkVar.3,v 1.9.2.2 2005/09/09 18:48:40 dgp Exp $ '\" .so man.macros .TH Tcl_LinkVar 3 7.5 Tcl "Tcl Library Procedures" @@ -28,14 +28,23 @@ int Interpreter that contains \fIvarName\fR. Also used by \fBTcl_LinkVar\fR to return error messages. .AP "const char" *varName in -Name of global variable. +Name of global variable. .AP char *addr in Address of C variable that is to be linked to \fIvarName\fR. .AP int type in -Type of C variable. Must be one of \fBTCL_LINK_INT\fR, \fBTCL_LINK_DOUBLE\fR, +Type of C variable. Must be one of \fBTCL_LINK_INT\fR, +.VS 8.5 +\fBTCL_LINK_UINT\fR, \fBTCL_LINK_CHAR\fR, \fBTCL_LINK_UCHAR\fR, +\fBTCL_LINK_SHORT\fR, \fBTCL_LINK_USHORT\fR, \fBTCL_LINK_LONG\fR, +\fBTCL_LINK_ULONG\fR, +.VE 8.5 \fBTCL_LINK_WIDE_INT\fR, -\fBTCL_LINK_BOOLEAN\fR, or \fBTCL_LINK_STRING\fR, optionally OR'ed with -\fBTCL_LINK_READ_ONLY\fR to make Tcl variable read-only. +.VS 8.5 +\fBTCL_LINK_WIDE_UINT\fR, \fBTCL_LINK_FLOAT\fR, +.VE 8.5 +\fBTCL_LINK_DOUBLE\fR, \fBTCL_LINK_BOOLEAN\fR, or +\fBTCL_LINK_STRING\fR, optionally OR'ed with \fBTCL_LINK_READ_ONLY\fR +to make Tcl variable read-only. .BE .SH DESCRIPTION @@ -61,6 +70,61 @@ Any value written into the Tcl variable must have a proper integer form acceptable to \fBTcl_GetIntFromObj\fR; attempts to write non-integer values into \fIvarName\fR will be rejected with Tcl errors. +.VS 8.5 +.TP +\fBTCL_LINK_UINT\fR +The C variable is of type \fBunsigned int\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the +platform's defined range for the \fBunsigned int\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_CHAR\fR +The C variable is of type \fBchar\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the +\fBchar\fR datatype; attempts to write non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_UCHAR\fR +The C variable is of type \fBunsigned char\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetIntFromObj\fR and in the +platform's defined range for the \fBunsigned char\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_SHORT\fR +The C variable is of type \fBshort\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the +\fBshort\fR datatype; attempts to write non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_USHORT\fR +The C variable is of type \fBunsigned short\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetIntFromObj\fR and in the +platform's defined range for the \fBunsigned short\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_LONG\fR +The C variable is of type \fBlong\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetLongFromObj\fR; attempts to write +non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. +.TP +\fBTCL_LINK_ULONG\fR +The C variable is of type \fBunsigned long\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the +platform's defined range for the \fBunsigned long\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. +.VE 8.5 .TP \fBTCL_LINK_DOUBLE\fR The C variable is of type \fBdouble\fR. @@ -68,6 +132,16 @@ Any value written into the Tcl variable must have a proper real form acceptable to \fBTcl_GetDoubleFromObj\fR; attempts to write non-real values into \fIvarName\fR will be rejected with Tcl errors. +.VS 8.5 +.TP +\fBTCL_LINK_FLOAT\fR +The C variable is of type \fBfloat\fR. +Any value written into the Tcl variable must have a proper real +form acceptable to \fBTcl_GetDoubleFromObj\fR and must be within the +range acceptable for a \fBfloat\fR; attempts to +write non-real values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. +.VE 8.5 .TP \fBTCL_LINK_WIDE_INT\fR The C variable is of type \fBTcl_WideInt\fR (which is an integer type @@ -76,6 +150,19 @@ Any value written into the Tcl variable must have a proper integer form acceptable to \fBTcl_GetWideIntFromObj\fR; attempts to write non-integer values into \fIvarName\fR will be rejected with Tcl errors. +.VS 8.5 +.TP +\fBTCL_LINK_WIDE_UINT\fR +The C variable is of type \fBTcl_WideUInt\fR (which is an unsigned +integer type at least 64-bits wide on all platforms that can support +it.) +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR (it will be +cast to unsigned); +'\" FIXME! Use bignums instead. +attempts to write non-integer values into \fIvarName\fR will be +rejected with Tcl errors. +.VE 8.5 .TP \fBTCL_LINK_BOOLEAN\fR The C variable is of type \fBint\fR. diff --git a/generic/tcl.h b/generic/tcl.h index fb41cbf..6264be8 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -1,8 +1,8 @@ /* * tcl.h -- * - * This header file describes the externally-visible facilities - * of the Tcl interpreter. + * This header file describes the externally-visible facilities of the + * Tcl interpreter. * * Copyright (c) 1987-1994 The Regents of the University of California. * Copyright (c) 1993-1996 Lucent Technologies. @@ -10,18 +10,18 @@ * Copyright (c) 1998-2000 by Scriptics Corporation. * Copyright (c) 2002 by Kevin B. Kenny. All rights reserved. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tcl.h,v 1.191.2.8 2005/07/12 20:36:18 kennykb Exp $ + * RCS: @(#) $Id: tcl.h,v 1.191.2.9 2005/09/09 18:48:40 dgp Exp $ */ #ifndef _TCL #define _TCL /* - * * For C++ compilers, use extern "C" - * */ + * For C++ compilers, use extern "C" + */ #ifdef __cplusplus extern "C" { @@ -36,8 +36,8 @@ extern "C" { #define TCL_FINAL_RELEASE 2 /* - * When version numbers change here, must also go into the following files - * and update the version numbers: + * When version numbers change here, must also go into the following files and + * update the version numbers: * * library/init.tcl (only if Major.minor changes, not patchlevel) 1 LOC * unix/configure.in (2 LOC Major, 2 LOC minor, 1 LOC patch) @@ -54,6 +54,7 @@ extern "C" { * tools/tcl.wse.in (for windows installer) * tools/tclSplash.bmp (not patchlevel) */ + #define TCL_MAJOR_VERSION 8 #define TCL_MINOR_VERSION 5 #define TCL_RELEASE_LEVEL TCL_ALPHA_RELEASE @@ -63,8 +64,8 @@ extern "C" { #define TCL_PATCH_LEVEL "8.5a4" /* - * The following definitions set up the proper options for Windows - * compilers. We use this method because there is no autoconf equivalent. + * The following definitions set up the proper options for Windows compilers. + * We use this method because there is no autoconf equivalent. */ #ifndef __WIN32__ @@ -82,6 +83,7 @@ extern "C" { /* * STRICT: See MSDN Article Q83456 */ + #ifdef __WIN32__ # ifndef STRICT # define STRICT @@ -92,6 +94,7 @@ extern "C" { * Utility macros: STRINGIFY takes an argument and wraps it in "" (double * quotation marks), JOIN joins two arguments. */ + #ifndef STRINGIFY # define STRINGIFY(x) STRINGIFY1(x) # define STRINGIFY1(x) #x @@ -101,20 +104,20 @@ extern "C" { # define JOIN1(a,b) a##b #endif -/* - * A special definition used to allow this header file to be included - * from windows resource files so that they can obtain version - * information. RC_INVOKED is defined by default by the windows RC tool. +/* + * A special definition used to allow this header file to be included from + * windows resource files so that they can obtain version information. + * RC_INVOKED is defined by default by the windows RC tool. * - * Resource compilers don't like all the C stuff, like typedefs and - * procedure declarations, that occur below, so block them out. + * Resource compilers don't like all the C stuff, like typedefs and function + * declarations, that occur below, so block them out. */ #ifndef RC_INVOKED /* - * Special macro to define mutexes, that doesn't do anything - * if we are not using threads. + * Special macro to define mutexes, that doesn't do anything if we are not + * using threads. */ #ifdef TCL_THREADS @@ -124,8 +127,8 @@ extern "C" { #endif /* - * Macros that eliminate the overhead of the thread synchronization - * functions when compiling without thread support. + * Macros that eliminate the overhead of the thread synchronization functions + * when compiling without thread support. */ #ifndef TCL_THREADS @@ -138,25 +141,27 @@ extern "C" { #endif /* TCL_THREADS */ /* - * Tcl's public routine Tcl_FSSeek() uses the values SEEK_SET, - * SEEK_CUR, and SEEK_END, all #define'd by stdio.h . + * Tcl's public routine Tcl_FSSeek() uses the values SEEK_SET, SEEK_CUR, and + * SEEK_END, all #define'd by stdio.h . * - * Also, many extensions need stdio.h, and they've grown accustomed - * to tcl.h providing it for them rather than #include-ing it themselves - * as they should, so also for their sake, we keep the #include to be - * consistent with prior Tcl releases. + * Also, many extensions need stdio.h, and they've grown accustomed to tcl.h + * providing it for them rather than #include-ing it themselves as they + * should, so also for their sake, we keep the #include to be consistent with + * prior Tcl releases. */ + #include /* - * Definitions that allow Tcl functions with variable numbers of - * arguments to be used with either varargs.h or stdarg.h. TCL_VARARGS - * is used in procedure prototypes. TCL_VARARGS_DEF is used to declare - * the arguments in a function definiton: it takes the type and name of - * the first argument and supplies the appropriate argument declaration - * string for use in the function definition. TCL_VARARGS_START - * initializes the va_list data structure and returns the first argument. + * Definitions that allow Tcl functions with variable numbers of arguments to + * be used with either varargs.h or stdarg.h. TCL_VARARGS is used in function + * prototypes. TCL_VARARGS_DEF is used to declare the arguments in a function + * definiton: it takes the type and name of the first argument and supplies + * the appropriate argument declaration string for use in the function + * definition. TCL_VARARGS_START initializes the va_list data structure and + * returns the first argument. */ + #if !defined(NO_STDARG) # include # define TCL_VARARGS(type, name) (type name, ...) @@ -164,18 +169,18 @@ extern "C" { # define TCL_VARARGS_START(type, name, list) (va_start(list, name), name) #else # include -# define TCL_VARARGS(type, name) () -# define TCL_VARARGS_DEF(type, name) (va_alist) +# define TCL_VARARGS(type, name) () +# define TCL_VARARGS_DEF(type, name) (va_alist) # define TCL_VARARGS_START(type, name, list) \ (va_start(list), va_arg(list, type)) #endif /* - * Macros used to declare a function to be exported by a DLL. - * Used by Windows, maps to no-op declarations on non-Windows systems. - * The default build on windows is for a DLL, which causes the DLLIMPORT - * and DLLEXPORT macros to be nonempty. To build a static library, the - * macro STATIC_BUILD should be defined. + * Macros used to declare a function to be exported by a DLL. Used by Windows, + * maps to no-op declarations on non-Windows systems. The default build on + * windows is for a DLL, which causes the DLLIMPORT and DLLEXPORT macros to be + * nonempty. To build a static library, the macro STATIC_BUILD should be + * defined. */ #ifdef STATIC_BUILD @@ -193,19 +198,20 @@ extern "C" { /* * These macros are used to control whether functions are being declared for - * import or export. If a function is being declared while it is being built + * import or export. If a function is being declared while it is being built * to be included in a shared library, then it should have the DLLEXPORT - * storage class. If is being declared for use by a module that is going to + * storage class. If is being declared for use by a module that is going to * link against the shared library, then it should have the DLLIMPORT storage - * class. If the symbol is beind declared for a static build or for use from a + * class. If the symbol is beind declared for a static build or for use from a * stub library, then the storage class should be empty. * - * The convention is that a macro called BUILD_xxxx, where xxxx is the - * name of a library we are building, is set on the compile line for sources - * that are to be placed in the library. When this macro is set, the - * storage class will be set to DLLEXPORT. At the end of the header file, the - * storage class will be reset to DLLIMPORT. + * The convention is that a macro called BUILD_xxxx, where xxxx is the name of + * a library we are building, is set on the compile line for sources that are + * to be placed in the library. When this macro is set, the storage class will + * be set to DLLEXPORT. At the end of the header file, the storage class will + * be reset to DLLIMPORT. */ + #undef TCL_STORAGE_CLASS #ifdef BUILD_tcl # define TCL_STORAGE_CLASS DLLEXPORT @@ -217,11 +223,11 @@ extern "C" { # endif #endif - /* - * Definitions that allow this header file to be used either with or - * without ANSI C features like function prototypes. + * Definitions that allow this header file to be used either with or without + * ANSI C features like function prototypes. */ + #undef _ANSI_ARGS_ #undef CONST #ifndef INLINE @@ -248,7 +254,7 @@ extern "C" { # define CONST84_RETURN #else # ifdef USE_COMPAT_CONST -# define CONST84 +# define CONST84 # define CONST84_RETURN CONST # else # define CONST84 CONST @@ -256,10 +262,10 @@ extern "C" { # endif #endif - /* * Make sure EXTERN isn't defined elsewhere */ + #ifdef EXTERN # undef EXTERN #endif /* EXTERN */ @@ -270,15 +276,12 @@ extern "C" { # define EXTERN extern TCL_STORAGE_CLASS #endif - /* - * The following code is copied from winnt.h. - * If we don't replicate it here, then can't be included - * after tcl.h, since tcl.h also defines VOID. - * This block is skipped under Cygwin and Mingw. - * - * + * The following code is copied from winnt.h. If we don't replicate it here, + * then can't be included after tcl.h, since tcl.h also defines + * VOID. This block is skipped under Cygwin and Mingw. */ + #if defined(__WIN32__) && !defined(HAVE_WINNT_IGNORE_VOID) #ifndef VOID #define VOID void @@ -289,20 +292,20 @@ typedef long LONG; #endif /* __WIN32__ && !HAVE_WINNT_IGNORE_VOID */ /* - * Macro to use instead of "void" for arguments that must have - * type "void *" in ANSI C; maps them to type "char *" in - * non-ANSI systems. + * Macro to use instead of "void" for arguments that must have type "void *" + * in ANSI C; maps them to type "char *" in non-ANSI systems. */ #ifndef NO_VOID -# define VOID void +#define VOID void #else -# define VOID char +#define VOID char #endif /* * Miscellaneous declarations. */ + #ifndef NULL # define NULL 0 #endif @@ -317,13 +320,13 @@ typedef long LONG; #endif /* - * Define Tcl_WideInt to be a type that is (at least) 64-bits wide, - * and define Tcl_WideUInt to be the unsigned variant of that type - * (assuming that where we have one, we can have the other.) + * Define Tcl_WideInt to be a type that is (at least) 64-bits wide, and define + * Tcl_WideUInt to be the unsigned variant of that type (assuming that where + * we have one, we can have the other.) * * Also defines the following macros: - * TCL_WIDE_INT_IS_LONG - if wide ints are really longs (i.e. we're on - * a real 64-bit system.) + * TCL_WIDE_INT_IS_LONG - if wide ints are really longs (i.e. we're on a real + * 64-bit system.) * Tcl_WideAsLong - forgetful converter from wideInt to long. * Tcl_LongAsWide - sign-extending converter from long to wideInt. * Tcl_WideAsDouble - converter from wideInt to double. @@ -332,12 +335,12 @@ typedef long LONG; * The following invariant should hold for any long value 'longVal': * longVal == Tcl_WideAsLong(Tcl_LongAsWide(longVal)) * - * Note on converting between Tcl_WideInt and strings. This - * implementation (in tclObj.c) depends on the functions strtoull() - * and sprintf(...,"%" TCL_LL_MODIFIER "d",...). TCL_LL_MODIFIER_SIZE - * is the length of the modifier string, which is "ll" on most 32-bit - * Unix systems. It has to be split up like this to allow for the more - * complex formats sometimes needed (e.g. in the format(n) command.) + * Note on converting between Tcl_WideInt and strings. This implementation (in + * tclObj.c) depends on the functions strtoull() and sprintf(...,"%" + * TCL_LL_MODIFIER "d",...). TCL_LL_MODIFIER_SIZE is the length of the + * modifier string, which is "ll" on most 32-bit Unix systems. It has to be + * split up like this to allow for the more complex formats sometimes needed + * (e.g. in the format(n) command.) */ #if !defined(TCL_WIDE_INT_TYPE)&&!defined(TCL_WIDE_INT_IS_LONG) @@ -364,8 +367,8 @@ typedef struct _stati64 Tcl_StatBuf; # endif /* __BORLANDC__ */ # else /* __WIN32__ */ /* - * Don't know what platform it is and configure hasn't discovered what - * is going on for us. Try to guess... + * Don't know what platform it is and configure hasn't discovered what is + * going on for us. Try to guess... */ # ifdef NO_LIMITS_H # error please define either TCL_WIDE_INT_TYPE or TCL_WIDE_INT_IS_LONG @@ -399,8 +402,8 @@ typedef struct stat Tcl_StatBuf; # endif /* !TCL_LL_MODIFIER */ #else /* TCL_WIDE_INT_IS_LONG */ /* - * The next short section of defines are only done when not running on - * Windows or some other strange platform. + * The next short section of defines are only done when not running on Windows + * or some other strange platform. */ # ifndef TCL_LL_MODIFIER # ifdef HAVE_STRUCT_STAT64 @@ -417,32 +420,31 @@ typedef struct stat Tcl_StatBuf; # define Tcl_DoubleAsWide(val) ((Tcl_WideInt)((double)(val))) #endif /* TCL_WIDE_INT_IS_LONG */ - /* * This flag controls whether binary compatability is maintained with - * extensions built against a previous version of Tcl. This is true - * by default. + * extensions built against a previous version of Tcl. This is true by + * default. */ + #ifndef TCL_PRESERVE_BINARY_COMPATABILITY # define TCL_PRESERVE_BINARY_COMPATABILITY 1 #endif - /* - * Data structures defined opaquely in this module. The definitions below - * just provide dummy types. A few fields are made visible in Tcl_Interp - * structures, namely those used for returning a string result from - * commands. Direct access to the result field is discouraged in Tcl 8.0. - * The interpreter result is either an object or a string, and the two - * values are kept consistent unless some C code sets interp->result - * directly. Programmers should use either the procedure Tcl_GetObjResult() - * or Tcl_GetStringResult() to read the interpreter's result. See the - * SetResult man page for details. - * - * Note: any change to the Tcl_Interp definition below must be mirrored - * in the "real" definition in tclInt.h. + * Data structures defined opaquely in this module. The definitions below just + * provide dummy types. A few fields are made visible in Tcl_Interp + * structures, namely those used for returning a string result from commands. + * Direct access to the result field is discouraged in Tcl 8.0. The + * interpreter result is either an object or a string, and the two values are + * kept consistent unless some C code sets interp->result directly. + * Programmers should use either the function Tcl_GetObjResult() or + * Tcl_GetStringResult() to read the interpreter's result. See the SetResult + * man page for details. + * + * Note: any change to the Tcl_Interp definition below must be mirrored in the + * "real" definition in tclInt.h. * - * Note: Tcl_ObjCmdProc procedures do not directly set result and freeProc. + * Note: Tcl_ObjCmdProc functions do not directly set result and freeProc. * Instead, they set a Tcl_Obj member in the "real" structure that can be * accessed with Tcl_GetObjResult() and Tcl_SetObjResult(). */ @@ -451,16 +453,16 @@ typedef struct Tcl_Interp { char *result; /* If the last command returned a string * result, this points to it. */ void (*freeProc) _ANSI_ARGS_((char *blockPtr)); - /* Zero means the string result is - * statically allocated. TCL_DYNAMIC means - * it was allocated with ckalloc and should - * be freed with ckfree. Other values give - * the address of procedure to invoke to - * free the result. Tcl_Eval must free it - * before executing next command. */ - int errorLine; /* When TCL_ERROR is returned, this gives - * the line number within the command where - * the error occurred (1 if first line). */ + /* Zero means the string result is statically + * allocated. TCL_DYNAMIC means it was + * allocated with ckalloc and should be freed + * with ckfree. Other values give the address + * of function to invoke to free the result. + * Tcl_Eval must free it before executing next + * command. */ + int errorLine; /* When TCL_ERROR is returned, this gives the + * line number within the command where the + * error occurred (1 if first line). */ } Tcl_Interp; typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler; @@ -484,43 +486,44 @@ typedef struct Tcl_Trace_ *Tcl_Trace; typedef struct Tcl_Var_ *Tcl_Var; /* - * Definition of the interface to procedures implementing threads. - * A procedure following this definition is given to each call of - * 'Tcl_CreateThread' and will be called as the main fuction of - * the new thread created by that call. + * Definition of the interface to functions implementing threads. A function + * following this definition is given to each call of 'Tcl_CreateThread' and + * will be called as the main fuction of the new thread created by that call. */ + #if defined __WIN32__ typedef unsigned (__stdcall Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData)); #else typedef void (Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData)); #endif - /* * Threading function return types used for abstracting away platform - * differences when writing a Tcl_ThreadCreateProc. See the NewThread - * function in generic/tclThreadTest.c for it's usage. + * differences when writing a Tcl_ThreadCreateProc. See the NewThread function + * in generic/tclThreadTest.c for it's usage. */ + #if defined __WIN32__ # define Tcl_ThreadCreateType unsigned __stdcall # define TCL_THREAD_CREATE_RETURN return 0 #else # define Tcl_ThreadCreateType void -# define TCL_THREAD_CREATE_RETURN +# define TCL_THREAD_CREATE_RETURN #endif - /* * Definition of values for default stacksize and the possible flags to be * given to Tcl_CreateThread. */ + #define TCL_THREAD_STACK_DEFAULT (0) /* Use default size for stack */ -#define TCL_THREAD_NOFLAGS (0000) /* Standard flags, default behaviour */ -#define TCL_THREAD_JOINABLE (0001) /* Mark the thread as joinable */ +#define TCL_THREAD_NOFLAGS (0000) /* Standard flags, default behaviour */ +#define TCL_THREAD_JOINABLE (0001) /* Mark the thread as joinable */ /* * Flag values passed to Tcl_GetRegExpFromObj. */ + #define TCL_REG_BASIC 000000 /* BREs (convenience) */ #define TCL_REG_EXTENDED 000001 /* EREs */ #define TCL_REG_ADVF 000002 /* advanced features in EREs */ @@ -537,9 +540,10 @@ typedef void (Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData)); * matches */ /* - * The following flag is experimental and only intended for use by Expect. It + * The following flag is experimental and only intended for use by Expect. It * will probably go away in a later release. */ + #define TCL_REG_BOSONLY 002000 /* prepend \A to pattern so it only * matches at the beginning of the * string. */ @@ -547,57 +551,60 @@ typedef void (Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData)); /* * Flags values passed to Tcl_RegExpExecObj. */ + #define TCL_REG_NOTBOL 0001 /* Beginning of string does not match ^. */ #define TCL_REG_NOTEOL 0002 /* End of string does not match $. */ /* - * Structures filled in by Tcl_RegExpInfo. Note that all offset values are - * relative to the start of the match string, not the beginning of the - * entire string. + * Structures filled in by Tcl_RegExpInfo. Note that all offset values are + * relative to the start of the match string, not the beginning of the entire + * string. */ + typedef struct Tcl_RegExpIndices { - long start; /* character offset of first character in match */ - long end; /* character offset of first character after the - * match. */ + long start; /* Character offset of first character in + * match. */ + long end; /* Character offset of first character after + * the match. */ } Tcl_RegExpIndices; typedef struct Tcl_RegExpInfo { - int nsubs; /* number of subexpressions in the - * compiled expression */ - Tcl_RegExpIndices *matches; /* array of nsubs match offset - * pairs */ - long extendStart; /* The offset at which a subsequent - * match might begin. */ + int nsubs; /* Number of subexpressions in the compiled + * expression. */ + Tcl_RegExpIndices *matches; /* Array of nsubs match offset pairs. */ + long extendStart; /* The offset at which a subsequent match + * might begin. */ long reserved; /* Reserved for later use. */ } Tcl_RegExpInfo; /* - * Picky compilers complain if this typdef doesn't appear before the - * struct's reference in tclDecls.h. + * Picky compilers complain if this typdef doesn't appear before the struct's + * reference in tclDecls.h. */ + typedef Tcl_StatBuf *Tcl_Stat_; typedef struct stat *Tcl_OldStat_; /* * When a TCL command returns, the interpreter contains a result from the - * command. Programmers are strongly encouraged to use one of the - * procedures Tcl_GetObjResult() or Tcl_GetStringResult() to read the - * interpreter's result. See the SetResult man page for details. Besides - * this result, the command procedure returns an integer code, which is - * one of the following: + * command. Programmers are strongly encouraged to use one of the functions + * Tcl_GetObjResult() or Tcl_GetStringResult() to read the interpreter's + * result. See the SetResult man page for details. Besides this result, the + * command function returns an integer code, which is one of the following: * - * TCL_OK Command completed normally; the interpreter's - * result contains the command's result. - * TCL_ERROR The command couldn't be completed successfully; - * the interpreter's result describes what went wrong. - * TCL_RETURN The command requests that the current procedure - * return; the interpreter's result contains the - * procedure's return value. - * TCL_BREAK The command requests that the innermost loop - * be exited; the interpreter's result is meaningless. - * TCL_CONTINUE Go on to the next iteration of the current loop; - * the interpreter's result is meaningless. + * TCL_OK Command completed normally; the interpreter's result + * contains the command's result. + * TCL_ERROR The command couldn't be completed successfully; the + * interpreter's result describes what went wrong. + * TCL_RETURN The command requests that the current function return; + * the interpreter's result contains the function's + * return value. + * TCL_BREAK The command requests that the innermost loop be + * exited; the interpreter's result is meaningless. + * TCL_CONTINUE Go on to the next iteration of the current loop; the + * interpreter's result is meaningless. */ + #define TCL_OK 0 #define TCL_ERROR 1 #define TCL_RETURN 2 @@ -609,21 +616,23 @@ typedef struct stat *Tcl_OldStat_; /* * Flags to control what substitutions are performed by Tcl_SubstObj(): */ + #define TCL_SUBST_COMMANDS 001 #define TCL_SUBST_VARIABLES 002 #define TCL_SUBST_BACKSLASHES 004 #define TCL_SUBST_ALL 007 - /* * Argument descriptors for math function callbacks in expressions: */ + typedef enum { TCL_INT, TCL_DOUBLE, TCL_EITHER, TCL_WIDE_INT } Tcl_ValueType; + typedef struct Tcl_Value { - Tcl_ValueType type; /* Indicates intValue or doubleValue is - * valid, or both. */ + Tcl_ValueType type; /* Indicates intValue or doubleValue is valid, + * or both. */ long intValue; /* Integer value. */ double doubleValue; /* Double-precision floating value. */ Tcl_WideInt wideValue; /* Wide (min. 64-bit) integer value. */ @@ -631,14 +640,13 @@ typedef struct Tcl_Value { /* * Forward declaration of Tcl_Obj to prevent an error when the forward - * reference to Tcl_Obj is encountered in the procedure types declared - * below. + * reference to Tcl_Obj is encountered in the function types declared below. */ -struct Tcl_Obj; +struct Tcl_Obj; /* - * Procedure types defined by Tcl: + * Function types defined by Tcl: */ typedef int (Tcl_AppInitProc) _ANSI_ARGS_((Tcl_Interp *interp)); @@ -656,8 +664,8 @@ typedef int (Tcl_CmdObjTraceProc) _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int level, CONST char *command, Tcl_Command commandInfo, int objc, struct Tcl_Obj * CONST * objv)); typedef void (Tcl_CmdObjTraceDeleteProc) _ANSI_ARGS_((ClientData clientData)); -typedef void (Tcl_DupInternalRepProc) _ANSI_ARGS_((struct Tcl_Obj *srcPtr, - struct Tcl_Obj *dupPtr)); +typedef void (Tcl_DupInternalRepProc) _ANSI_ARGS_((struct Tcl_Obj *srcPtr, + struct Tcl_Obj *dupPtr)); typedef int (Tcl_EncodingConvertProc)_ANSI_ARGS_((ClientData clientData, CONST char *src, int srcLen, int flags, Tcl_EncodingState *statePtr, char *dst, int dstLen, int *srcReadPtr, int *dstWrotePtr, @@ -667,7 +675,7 @@ typedef int (Tcl_EventProc) _ANSI_ARGS_((Tcl_Event *evPtr, int flags)); typedef void (Tcl_EventCheckProc) _ANSI_ARGS_((ClientData clientData, int flags)); typedef int (Tcl_EventDeleteProc) _ANSI_ARGS_((Tcl_Event *evPtr, - ClientData clientData)); + ClientData clientData)); typedef void (Tcl_EventSetupProc) _ANSI_ARGS_((ClientData clientData, int flags)); typedef void (Tcl_ExitProc) _ANSI_ARGS_((ClientData clientData)); @@ -685,16 +693,17 @@ typedef int (Tcl_ObjCmdProc) _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)); typedef int (Tcl_PackageInitProc) _ANSI_ARGS_((Tcl_Interp *interp)); typedef int (Tcl_PackageUnloadProc) _ANSI_ARGS_((Tcl_Interp *interp, - int flags)); + int flags)); typedef void (Tcl_PanicProc) _ANSI_ARGS_(TCL_VARARGS(CONST char *, format)); typedef void (Tcl_TcpAcceptProc) _ANSI_ARGS_((ClientData callbackData, - Tcl_Channel chan, char *address, int port)); + Tcl_Channel chan, char *address, int port)); typedef void (Tcl_TimerProc) _ANSI_ARGS_((ClientData clientData)); typedef int (Tcl_SetFromAnyProc) _ANSI_ARGS_((Tcl_Interp *interp, struct Tcl_Obj *objPtr)); typedef void (Tcl_UpdateStringProc) _ANSI_ARGS_((struct Tcl_Obj *objPtr)); typedef char *(Tcl_VarTraceProc) _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, CONST84 char *part1, CONST84 char *part2, int flags)); + Tcl_Interp *interp, CONST84 char *part1, CONST84 char *part2, + int flags)); typedef void (Tcl_CommandTraceProc) _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, CONST char *oldName, CONST char *newName, int flags)); @@ -707,37 +716,34 @@ typedef ClientData (Tcl_InitNotifierProc) _ANSI_ARGS_((VOID)); typedef void (Tcl_FinalizeNotifierProc) _ANSI_ARGS_((ClientData clientData)); typedef void (Tcl_MainLoopProc) _ANSI_ARGS_((void)); - /* - * The following structure represents a type of object, which is a - * particular internal representation for an object plus a set of - * procedures that provide standard operations on objects of that type. + * The following structure represents a type of object, which is a particular + * internal representation for an object plus a set of functions that provide + * standard operations on objects of that type. */ typedef struct Tcl_ObjType { char *name; /* Name of the type, e.g. "int". */ Tcl_FreeInternalRepProc *freeIntRepProc; /* Called to free any storage for the type's - * internal rep. NULL if the internal rep - * does not need freeing. */ + * internal rep. NULL if the internal rep does + * not need freeing. */ Tcl_DupInternalRepProc *dupIntRepProc; - /* Called to create a new object as a copy - * of an existing object. */ + /* Called to create a new object as a copy of + * an existing object. */ Tcl_UpdateStringProc *updateStringProc; - /* Called to update the string rep from the + /* Called to update the string rep from the * type's internal representation. */ Tcl_SetFromAnyProc *setFromAnyProc; - /* Called to convert the object's internal - * rep to this type. Frees the internal rep - * of the old type. Returns TCL_ERROR on - * failure. */ + /* Called to convert the object's internal rep + * to this type. Frees the internal rep of the + * old type. Returns TCL_ERROR on failure. */ } Tcl_ObjType; - /* - * One of the following structures exists for each object in the Tcl - * system. An object stores a value as either a string, some internal - * representation, or both. + * One of the following structures exists for each object in the Tcl system. + * An object stores a value as either a string, some internal representation, + * or both. */ typedef struct Tcl_Obj { @@ -747,18 +753,18 @@ typedef struct Tcl_Obj { * must be followed by a null byte (i.e., at * offset length) but may also contain * embedded null characters. The array's - * storage is allocated by ckalloc. NULL - * means the string rep is invalid and must - * be regenerated from the internal rep. - * Clients should use Tcl_GetStringFromObj - * or Tcl_GetString to get a pointer to the - * byte array as a readonly value. */ + * storage is allocated by ckalloc. NULL means + * the string rep is invalid and must be + * regenerated from the internal rep. Clients + * should use Tcl_GetStringFromObj or + * Tcl_GetString to get a pointer to the byte + * array as a readonly value. */ int length; /* The number of bytes at *bytes, not * including the terminating null. */ Tcl_ObjType *typePtr; /* Denotes the object's type. Always * corresponds to the type of the object's - * internal rep. NULL indicates the object - * has no internal rep (has no type). */ + * internal rep. NULL indicates the object has + * no internal rep (has no type). */ union { /* The internal representation: */ long longValue; /* - an long integer value */ double doubleValue; /* - a double-precision floating value */ @@ -768,26 +774,26 @@ typedef struct Tcl_Obj { VOID *ptr1; VOID *ptr2; } twoPtrValue; - struct { /* - internal rep as a wide int, - * tightly packed fields */ + struct { /* - internal rep as a wide int, tightly + * packed fields */ VOID *digits; /* Pointer to digits */ - unsigned long misc; /* Alloc, used, and signum packed - * into a single word */ + unsigned long misc; /* Alloc, used, and signum packed into a + * single word */ } bignumValue; } internalRep; } Tcl_Obj; - /* - * Macros to increment and decrement a Tcl_Obj's reference count, and to - * test whether an object is shared (i.e. has reference count > 1). - * Note: clients should use Tcl_DecrRefCount() when they are finished using - * an object, and should never call TclFreeObj() directly. TclFreeObj() is - * only defined and made public in tcl.h to support Tcl_DecrRefCount's macro - * definition. Note also that Tcl_DecrRefCount() refers to the parameter - * "obj" twice. This means that you should avoid calling it with an - * expression that is expensive to compute or has side effects. + * Macros to increment and decrement a Tcl_Obj's reference count, and to test + * whether an object is shared (i.e. has reference count > 1). Note: clients + * should use Tcl_DecrRefCount() when they are finished using an object, and + * should never call TclFreeObj() directly. TclFreeObj() is only defined and + * made public in tcl.h to support Tcl_DecrRefCount's macro definition. Note + * also that Tcl_DecrRefCount() refers to the parameter "obj" twice. This + * means that you should avoid calling it with an expression that is expensive + * to compute or has side effects. */ + void Tcl_IncrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr)); void Tcl_DecrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr)); int Tcl_IsShared _ANSI_ARGS_((Tcl_Obj *objPtr)); @@ -809,9 +815,9 @@ int Tcl_IsShared _ANSI_ARGS_((Tcl_Obj *objPtr)); #endif /* - * Macros and definitions that help to debug the use of Tcl objects. - * When TCL_MEM_DEBUG is defined, the Tcl_New declarations are - * overridden to call debugging versions of the object creation procedures. + * Macros and definitions that help to debug the use of Tcl objects. When + * TCL_MEM_DEBUG is defined, the Tcl_New declarations are overridden to call + * debugging versions of the object creation functions. */ #ifdef TCL_MEM_DEBUG @@ -837,12 +843,12 @@ int Tcl_IsShared _ANSI_ARGS_((Tcl_Obj *objPtr)); Tcl_DbNewWideIntObj(val, __FILE__, __LINE__) #endif /* TCL_MEM_DEBUG */ - /* - * The following structure contains the state needed by - * Tcl_SaveResult. No-one outside of Tcl should access any of these - * fields. This structure is typically allocated on the stack. + * The following structure contains the state needed by Tcl_SaveResult. No-one + * outside of Tcl should access any of these fields. This structure is + * typically allocated on the stack. */ + typedef struct Tcl_SavedResult { char *result; Tcl_FreeProc *freeProc; @@ -853,49 +859,47 @@ typedef struct Tcl_SavedResult { char resultSpace[TCL_RESULT_SIZE+1]; } Tcl_SavedResult; - /* - * The following definitions support Tcl's namespace facility. - * Note: the first five fields must match exactly the fields in a - * Namespace structure (see tclInt.h). + * The following definitions support Tcl's namespace facility. Note: the first + * five fields must match exactly the fields in a Namespace structure (see + * tclInt.h). */ typedef struct Tcl_Namespace { - char *name; /* The namespace's name within its parent - * namespace. This contains no ::'s. The - * name of the global namespace is "" - * although "::" is an synonym. */ - char *fullName; /* The namespace's fully qualified name. - * This starts with ::. */ - ClientData clientData; /* Arbitrary value associated with this + char *name; /* The namespace's name within its parent + * namespace. This contains no ::'s. The name + * of the global namespace is "" although "::" + * is an synonym. */ + char *fullName; /* The namespace's fully qualified name. This + * starts with ::. */ + ClientData clientData; /* Arbitrary value associated with this * namespace. */ Tcl_NamespaceDeleteProc* deleteProc; - /* Procedure invoked when deleting the + /* Function invoked when deleting the * namespace to, e.g., free clientData. */ struct Tcl_Namespace* parentPtr; - /* Points to the namespace that contains - * this one. NULL if this is the global + /* Points to the namespace that contains this + * one. NULL if this is the global * namespace. */ } Tcl_Namespace; - /* - * The following structure represents a call frame, or activation record. - * A call frame defines a naming context for a procedure call: its local - * scope (for local variables) and its namespace scope (used for non-local - * variables; often the global :: namespace). A call frame can also define - * the naming context for a namespace eval or namespace inscope command: - * the namespace in which the command's code should execute. The - * Tcl_CallFrame structures exist only while procedures or namespace - * eval/inscope's are being executed, and provide a Tcl call stack. - * - * A call frame is initialized and pushed using Tcl_PushCallFrame and - * popped using Tcl_PopCallFrame. Storage for a Tcl_CallFrame must be - * provided by the Tcl_PushCallFrame caller, and callers typically allocate - * them on the C call stack for efficiency. For this reason, Tcl_CallFrame - * is defined as a structure and not as an opaque token. However, most - * Tcl_CallFrame fields are hidden since applications should not access - * them directly; others are declared as "dummyX". + * The following structure represents a call frame, or activation record. A + * call frame defines a naming context for a procedure call: its local scope + * (for local variables) and its namespace scope (used for non-local + * variables; often the global :: namespace). A call frame can also define the + * naming context for a namespace eval or namespace inscope command: the + * namespace in which the command's code should execute. The Tcl_CallFrame + * structures exist only while procedures or namespace eval/inscope's are + * being executed, and provide a Tcl call stack. + * + * A call frame is initialized and pushed using Tcl_PushCallFrame and popped + * using Tcl_PopCallFrame. Storage for a Tcl_CallFrame must be provided by the + * Tcl_PushCallFrame caller, and callers typically allocate them on the C call + * stack for efficiency. For this reason, Tcl_CallFrame is defined as a + * structure and not as an opaque token. However, most Tcl_CallFrame fields + * are hidden since applications should not access them directly; others are + * declared as "dummyX". * * WARNING!! The structure definition must be kept consistent with the * CallFrame structure in tclInt.h. If you change one, change the other. @@ -915,60 +919,58 @@ typedef struct Tcl_CallFrame { char* dummy10; } Tcl_CallFrame; - /* * Information about commands that is returned by Tcl_GetCommandInfo and - * passed to Tcl_SetCommandInfo. objProc is an objc/objv object-based - * command procedure while proc is a traditional Tcl argc/argv - * string-based procedure. Tcl_CreateObjCommand and Tcl_CreateCommand - * ensure that both objProc and proc are non-NULL and can be called to - * execute the command. However, it may be faster to call one instead of - * the other. The member isNativeObjectProc is set to 1 if an - * object-based procedure was registered by Tcl_CreateObjCommand, and to - * 0 if a string-based procedure was registered by Tcl_CreateCommand. - * The other procedure is typically set to a compatibility wrapper that - * does string-to-object or object-to-string argument conversions then - * calls the other procedure. + * passed to Tcl_SetCommandInfo. objProc is an objc/objv object-based command + * function while proc is a traditional Tcl argc/argv string-based function. + * Tcl_CreateObjCommand and Tcl_CreateCommand ensure that both objProc and + * proc are non-NULL and can be called to execute the command. However, it may + * be faster to call one instead of the other. The member isNativeObjectProc + * is set to 1 if an object-based function was registered by + * Tcl_CreateObjCommand, and to 0 if a string-based function was registered by + * Tcl_CreateCommand. The other function is typically set to a compatibility + * wrapper that does string-to-object or object-to-string argument conversions + * then calls the other function. */ typedef struct Tcl_CmdInfo { - int isNativeObjectProc; /* 1 if objProc was registered by a call to - * Tcl_CreateObjCommand; 0 otherwise. - * Tcl_SetCmdInfo does not modify this - * field. */ - Tcl_ObjCmdProc *objProc; /* Command's object-based procedure. */ - ClientData objClientData; /* ClientData for object proc. */ - Tcl_CmdProc *proc; /* Command's string-based procedure. */ - ClientData clientData; /* ClientData for string proc. */ + int isNativeObjectProc; /* 1 if objProc was registered by a call to + * Tcl_CreateObjCommand; 0 otherwise. + * Tcl_SetCmdInfo does not modify this + * field. */ + Tcl_ObjCmdProc *objProc; /* Command's object-based function. */ + ClientData objClientData; /* ClientData for object proc. */ + Tcl_CmdProc *proc; /* Command's string-based function. */ + ClientData clientData; /* ClientData for string proc. */ Tcl_CmdDeleteProc *deleteProc; - /* Procedure to call when command is - * deleted. */ - ClientData deleteData; /* Value to pass to deleteProc (usually - * the same as clientData). */ - Tcl_Namespace *namespacePtr; /* Points to the namespace that contains - * this command. Note that Tcl_SetCmdInfo - * will not change a command's namespace; - * use TclRenameCommand or Tcl_Eval (of - * 'rename') to do that. */ - + /* Function to call when command is + * deleted. */ + ClientData deleteData; /* Value to pass to deleteProc (usually the + * same as clientData). */ + Tcl_Namespace *namespacePtr;/* Points to the namespace that contains this + * command. Note that Tcl_SetCmdInfo will not + * change a command's namespace; use + * TclRenameCommand or Tcl_Eval (of 'rename') + * to do that. */ } Tcl_CmdInfo; /* - * The structure defined below is used to hold dynamic strings. The only - * field that clients should use is the string field, accessible via the - * macro Tcl_DStringValue. + * The structure defined below is used to hold dynamic strings. The only + * fields that clients should use are string and length, accessible via the + * macros Tcl_DStringValue and Tcl_DStringLength. */ + #define TCL_DSTRING_STATIC_SIZE 200 typedef struct Tcl_DString { - char *string; /* Points to beginning of string: either + char *string; /* Points to beginning of string: either * staticSpace below or a malloced array. */ int length; /* Number of non-NULL characters in the * string. */ int spaceAvl; /* Total number of bytes available for the * string and its terminating NULL char. */ char staticSpace[TCL_DSTRING_STATIC_SIZE]; - /* Space to use in common case where string - * is small. */ + /* Space to use in common case where string is + * small. */ } Tcl_DString; #define Tcl_DStringLength(dsPtr) ((dsPtr)->length) @@ -976,31 +978,34 @@ typedef struct Tcl_DString { #define Tcl_DStringTrunc Tcl_DStringSetLength /* - * Definitions for the maximum number of digits of precision that may - * be specified in the "tcl_precision" variable, and the number of - * bytes of buffer space required by Tcl_PrintDouble. + * Definitions for the maximum number of digits of precision that may be + * specified in the "tcl_precision" variable, and the number of bytes of + * buffer space required by Tcl_PrintDouble. */ + #define TCL_MAX_PREC 17 #define TCL_DOUBLE_SPACE (TCL_MAX_PREC+10) /* * Definition for a number of bytes of buffer space sufficient to hold the - * string representation of an integer in base 10 (assuming the existence - * of 64-bit integers). + * string representation of an integer in base 10 (assuming the existence of + * 64-bit integers). */ + #define TCL_INTEGER_SPACE 24 /* * Flag values passed to Tcl_ConvertElement. - * TCL_DONT_USE_BRACES forces it not to enclose the element in braces, but - * to use backslash quoting instead. - * TCL_DONT_QUOTE_HASH disables the default quoting of the '#' character. - * It is safe to leave the hash unquoted when the element is not the - * first element of a list, and this flag can be used by the caller to - * indicated that condition. - * (careful! if you change these flag values be sure to change the - * definitions at the front of tclUtil.c). + * TCL_DONT_USE_BRACES forces it not to enclose the element in braces, but to + * use backslash quoting instead. + * TCL_DONT_QUOTE_HASH disables the default quoting of the '#' character. It + * is safe to leave the hash unquoted when the element is not the first + * element of a list, and this flag can be used by the caller to indicate + * that condition. + * (Careful! If you change these flag values be sure to change the definitions + * at the front of tclUtil.c). */ + #define TCL_DONT_USE_BRACES 1 #define TCL_DONT_QUOTE_HASH 8 @@ -1008,12 +1013,13 @@ typedef struct Tcl_DString { * Flag that may be passed to Tcl_GetIndexFromObj to force it to disallow * abbreviated strings. */ + #define TCL_EXACT 1 /* * Flag values passed to Tcl_RecordAndEval, Tcl_EvalObj, Tcl_EvalObjv. - * WARNING: these bit choices must not conflict with the bit choices - * for evalFlag bits in tclInt.h!! + * WARNING: these bit choices must not conflict with the bit choices for + * evalFlag bits in tclInt.h! * * Meanings: * TCL_NO_EVAL: Just record this command @@ -1031,16 +1037,18 @@ typedef struct Tcl_DString { #define TCL_EVAL_INVOKE 0x80000 /* - * Special freeProc values that may be passed to Tcl_SetResult (see - * the man page for details): + * Special freeProc values that may be passed to Tcl_SetResult (see the man + * page for details): */ + #define TCL_VOLATILE ((Tcl_FreeProc *) 1) #define TCL_STATIC ((Tcl_FreeProc *) 0) #define TCL_DYNAMIC ((Tcl_FreeProc *) 3) /* - * Flag values passed to variable-related procedures. + * Flag values passed to variable-related functions. */ + #define TCL_GLOBAL_ONLY 1 #define TCL_NAMESPACE_ONLY 2 #define TCL_APPEND_VALUE 4 @@ -1063,12 +1071,13 @@ typedef struct Tcl_DString { /* * Flag values for ensemble commands. */ + #define TCL_ENSEMBLE_PREFIX 0x02/* Flag value to say whether to allow * unambiguous prefixes of commands or to * require exact matches for command names. */ /* - * Flag values passed to command-related procedures. + * Flag values passed to command-related functions. */ #define TCL_TRACE_RENAME 0x2000 @@ -1077,31 +1086,40 @@ typedef struct Tcl_DString { #define TCL_ALLOW_INLINE_COMPILATION 0x20000 /* - * The TCL_PARSE_PART1 flag is deprecated and has no effect. - * The part1 is now always parsed whenever the part2 is NULL. - * (This is to avoid a common error when converting code to - * use the new object based APIs and forgetting to give the - * flag) + * The TCL_PARSE_PART1 flag is deprecated and has no effect. The part1 is now + * always parsed whenever the part2 is NULL. (This is to avoid a common error + * when converting code to use the new object based APIs and forgetting to + * give the flag) */ + #ifndef TCL_NO_DEPRECATED -# define TCL_PARSE_PART1 0x400 +# define TCL_PARSE_PART1 0x400 #endif - /* * Types for linked variables: */ + #define TCL_LINK_INT 1 #define TCL_LINK_DOUBLE 2 #define TCL_LINK_BOOLEAN 3 #define TCL_LINK_STRING 4 #define TCL_LINK_WIDE_INT 5 +#define TCL_LINK_CHAR 6 +#define TCL_LINK_UCHAR 7 +#define TCL_LINK_SHORT 8 +#define TCL_LINK_USHORT 9 +#define TCL_LINK_UINT 10 +#define TCL_LINK_LONG 11 +#define TCL_LINK_ULONG 12 +#define TCL_LINK_FLOAT 13 +#define TCL_LINK_WIDE_UINT 14 #define TCL_LINK_READ_ONLY 0x80 - /* * Forward declarations of Tcl_HashTable and related types. */ + typedef struct Tcl_HashKeyType Tcl_HashKeyType; typedef struct Tcl_HashTable Tcl_HashTable; typedef struct Tcl_HashEntry Tcl_HashEntry; @@ -1116,175 +1134,169 @@ typedef void (Tcl_FreeHashEntryProc) _ANSI_ARGS_((Tcl_HashEntry *hPtr)); /* * This flag controls whether the hash table stores the hash of a key, or - * recalculates it. There should be no reason for turning this flag off - * as it is completely binary and source compatible unless you directly - * access the bucketPtr member of the Tcl_HashTableEntry structure. This - * member has been removed and the space used to store the hash value. + * recalculates it. There should be no reason for turning this flag off as it + * is completely binary and source compatible unless you directly access the + * bucketPtr member of the Tcl_HashTableEntry structure. This member has been + * removed and the space used to store the hash value. */ + #ifndef TCL_HASH_KEY_STORE_HASH # define TCL_HASH_KEY_STORE_HASH 1 #endif /* - * Structure definition for an entry in a hash table. No-one outside - * Tcl should access any of these fields directly; use the macros - * defined below. + * Structure definition for an entry in a hash table. No-one outside Tcl + * should access any of these fields directly; use the macros defined below. */ struct Tcl_HashEntry { - Tcl_HashEntry *nextPtr; /* Pointer to next entry in this - * hash bucket, or NULL for end of - * chain. */ - Tcl_HashTable *tablePtr; /* Pointer to table containing entry. */ + Tcl_HashEntry *nextPtr; /* Pointer to next entry in this hash bucket, + * or NULL for end of chain. */ + Tcl_HashTable *tablePtr; /* Pointer to table containing entry. */ #if TCL_HASH_KEY_STORE_HASH # if TCL_PRESERVE_BINARY_COMPATABILITY - VOID *hash; /* Hash value, stored as pointer to - * ensure that the offsets of the - * fields in this structure are not - * changed. */ + VOID *hash; /* Hash value, stored as pointer to ensure + * that the offsets of the fields in this + * structure are not changed. */ # else - unsigned int hash; /* Hash value. */ + unsigned int hash; /* Hash value. */ # endif #else - Tcl_HashEntry **bucketPtr; /* Pointer to bucket that points to - * first entry in this entry's chain: - * used for deleting the entry. */ + Tcl_HashEntry **bucketPtr; /* Pointer to bucket that points to first + * entry in this entry's chain: used for + * deleting the entry. */ #endif - ClientData clientData; /* Application stores something here - * with Tcl_SetHashValue. */ - union { /* Key has one of these forms: */ - char *oneWordValue; /* One-word value for key. */ - Tcl_Obj *objPtr; /* Tcl_Obj * key value. */ - int words[1]; /* Multiple integer words for key. - * The actual size will be as large - * as necessary for this table's - * keys. */ - char string[4]; /* String for key. The actual size - * will be as large as needed to hold - * the key. */ - } key; /* MUST BE LAST FIELD IN RECORD!! */ + ClientData clientData; /* Application stores something here with + * Tcl_SetHashValue. */ + union { /* Key has one of these forms: */ + char *oneWordValue; /* One-word value for key. */ + Tcl_Obj *objPtr; /* Tcl_Obj * key value. */ + int words[1]; /* Multiple integer words for key. The actual + * size will be as large as necessary for this + * table's keys. */ + char string[4]; /* String for key. The actual size will be as + * large as needed to hold the key. */ + } key; /* MUST BE LAST FIELD IN RECORD!! */ }; /* * Flags used in Tcl_HashKeyType. * - * TCL_HASH_KEY_RANDOMIZE_HASH: + * TCL_HASH_KEY_RANDOMIZE_HASH - * There are some things, pointers for example * which don't hash well because they do not use * the lower bits. If this flag is set then the * hash table will attempt to rectify this by * randomising the bits and then using the upper * N bits as the index into the table. - * TCL_HASH_KEY_SYSTEM_HASH: - * If this flag is set then all memory internally + * TCL_HASH_KEY_SYSTEM_HASH - If this flag is set then all memory internally * allocated for the hash table that is not for an * entry will use the system heap. */ + #define TCL_HASH_KEY_RANDOMIZE_HASH 0x1 #define TCL_HASH_KEY_SYSTEM_HASH 0x2 /* - * Structure definition for the methods associated with a hash table - * key type. + * Structure definition for the methods associated with a hash table key type. */ + #define TCL_HASH_KEY_TYPE_VERSION 1 struct Tcl_HashKeyType { int version; /* Version of the table. If this structure is * extended in future then the version can be * used to distinguish between different - * structures. - */ - + * structures. */ int flags; /* Flags, see above for details. */ - - /* Calculates a hash value for the key. If this is NULL then the pointer - * itself is used as a hash value. - */ Tcl_HashKeyProc *hashKeyProc; - - /* Compares two keys and returns zero if they do not match, and non-zero - * if they do. If this is NULL then the pointers are compared. - */ + /* Calculates a hash value for the key. If + * this is NULL then the pointer itself is + * used as a hash value. */ Tcl_CompareHashKeysProc *compareKeysProc; - - /* Called to allocate memory for a new entry, i.e. if the key is a - * string then this could allocate a single block which contains enough - * space for both the entry and the string. Only the key field of the - * allocated Tcl_HashEntry structure needs to be filled in. If something - * else needs to be done to the key, i.e. incrementing a reference count - * then that should be done by this function. If this is NULL then Tcl_Alloc - * is used to allocate enough space for a Tcl_HashEntry and the key pointer - * is assigned to key.oneWordValue. - */ + /* Compares two keys and returns zero if they + * do not match, and non-zero if they do. If + * this is NULL then the pointers are + * compared. */ Tcl_AllocHashEntryProc *allocEntryProc; - - /* Called to free memory associated with an entry. If something else needs - * to be done to the key, i.e. decrementing a reference count then that - * should be done by this function. If this is NULL then Tcl_Free is used - * to free the Tcl_HashEntry. - */ + /* Called to allocate memory for a new entry, + * i.e. if the key is a string then this could + * allocate a single block which contains + * enough space for both the entry and the + * string. Only the key field of the allocated + * Tcl_HashEntry structure needs to be filled + * in. If something else needs to be done to + * the key, i.e. incrementing a reference + * count then that should be done by this + * function. If this is NULL then Tcl_Alloc is + * used to allocate enough space for a + * Tcl_HashEntry and the key pointer is + * assigned to key.oneWordValue. */ Tcl_FreeHashEntryProc *freeEntryProc; + /* Called to free memory associated with an + * entry. If something else needs to be done + * to the key, i.e. decrementing a reference + * count then that should be done by this + * function. If this is NULL then Tcl_Free is + * used to free the Tcl_HashEntry. */ }; /* - * Structure definition for a hash table. Must be in tcl.h so clients - * can allocate space for these structures, but clients should never - * access any fields in this structure. + * Structure definition for a hash table. Must be in tcl.h so clients can + * allocate space for these structures, but clients should never access any + * fields in this structure. */ #define TCL_SMALL_HASH_TABLE 4 struct Tcl_HashTable { - Tcl_HashEntry **buckets; /* Pointer to bucket array. Each - * element points to first entry in - * bucket's hash chain, or NULL. */ + Tcl_HashEntry **buckets; /* Pointer to bucket array. Each element + * points to first entry in bucket's hash + * chain, or NULL. */ Tcl_HashEntry *staticBuckets[TCL_SMALL_HASH_TABLE]; - /* Bucket array used for small tables - * (to avoid mallocs and frees). */ - int numBuckets; /* Total number of buckets allocated - * at **bucketPtr. */ - int numEntries; /* Total number of entries present - * in table. */ - int rebuildSize; /* Enlarge table when numEntries gets - * to be this large. */ - int downShift; /* Shift count used in hashing - * function. Designed to use high- - * order bits of randomized keys. */ - int mask; /* Mask value used in hashing - * function. */ - int keyType; /* Type of keys used in this table. - * It's either TCL_CUSTOM_KEYS, - * TCL_STRING_KEYS, TCL_ONE_WORD_KEYS, - * or an integer giving the number of - * ints that is the size of the key. - */ + /* Bucket array used for small tables (to + * avoid mallocs and frees). */ + int numBuckets; /* Total number of buckets allocated at + * **bucketPtr. */ + int numEntries; /* Total number of entries present in + * table. */ + int rebuildSize; /* Enlarge table when numEntries gets to be + * this large. */ + int downShift; /* Shift count used in hashing function. + * Designed to use high-order bits of + * randomized keys. */ + int mask; /* Mask value used in hashing function. */ + int keyType; /* Type of keys used in this table. It's + * either TCL_CUSTOM_KEYS, TCL_STRING_KEYS, + * TCL_ONE_WORD_KEYS, or an integer giving the + * number of ints that is the size of the + * key. */ #if TCL_PRESERVE_BINARY_COMPATABILITY Tcl_HashEntry *(*findProc) _ANSI_ARGS_((Tcl_HashTable *tablePtr, CONST char *key)); Tcl_HashEntry *(*createProc) _ANSI_ARGS_((Tcl_HashTable *tablePtr, CONST char *key, int *newPtr)); #endif - Tcl_HashKeyType *typePtr; /* Type of the keys used in the - * Tcl_HashTable. */ + Tcl_HashKeyType *typePtr; /* Type of the keys used in the + * Tcl_HashTable. */ }; /* - * Structure definition for information used to keep track of searches - * through hash tables: + * Structure definition for information used to keep track of searches through + * hash tables: */ typedef struct Tcl_HashSearch { - Tcl_HashTable *tablePtr; /* Table being searched. */ - int nextIndex; /* Index of next bucket to be - * enumerated after present one. */ - Tcl_HashEntry *nextEntryPtr; /* Next entry to be enumerated in the - * the current bucket. */ + Tcl_HashTable *tablePtr; /* Table being searched. */ + int nextIndex; /* Index of next bucket to be enumerated after + * present one. */ + Tcl_HashEntry *nextEntryPtr;/* Next entry to be enumerated in the current + * bucket. */ } Tcl_HashSearch; /* * Acceptable key types for hash tables: * - * TCL_STRING_KEYS: The keys are strings, they are copied into - * the entry. + * TCL_STRING_KEYS: The keys are strings, they are copied into the + * entry. * TCL_ONE_WORD_KEYS: The keys are pointers, the pointer is stored * in the entry. * TCL_CUSTOM_TYPE_KEYS: The keys are arbitrary types which are copied @@ -1292,25 +1304,24 @@ typedef struct Tcl_HashSearch { * TCL_CUSTOM_PTR_KEYS: The keys are pointers to arbitrary types, the * pointer is stored in the entry. * - * While maintaining binary compatability the above have to be distinct - * values as they are used to differentiate between old versions of the - * hash table which don't have a typePtr and new ones which do. Once binary - * compatability is discarded in favour of making more wide spread changes - * TCL_STRING_KEYS can be the same as TCL_CUSTOM_TYPE_KEYS, and - * TCL_ONE_WORD_KEYS can be the same as TCL_CUSTOM_PTR_KEYS because they - * simply determine how the key is accessed from the entry and not the - * behaviour. + * While maintaining binary compatability the above have to be distinct values + * as they are used to differentiate between old versions of the hash table + * which don't have a typePtr and new ones which do. Once binary compatability + * is discarded in favour of making more wide spread changes TCL_STRING_KEYS + * can be the same as TCL_CUSTOM_TYPE_KEYS, and TCL_ONE_WORD_KEYS can be the + * same as TCL_CUSTOM_PTR_KEYS because they simply determine how the key is + * accessed from the entry and not the behaviour. */ #define TCL_STRING_KEYS 0 #define TCL_ONE_WORD_KEYS 1 #if TCL_PRESERVE_BINARY_COMPATABILITY -# define TCL_CUSTOM_TYPE_KEYS -2 -# define TCL_CUSTOM_PTR_KEYS -1 +# define TCL_CUSTOM_TYPE_KEYS -2 +# define TCL_CUSTOM_PTR_KEYS -1 #else -# define TCL_CUSTOM_TYPE_KEYS TCL_STRING_KEYS -# define TCL_CUSTOM_PTR_KEYS TCL_ONE_WORD_KEYS +# define TCL_CUSTOM_TYPE_KEYS TCL_STRING_KEYS +# define TCL_CUSTOM_PTR_KEYS TCL_ONE_WORD_KEYS #endif /* @@ -1333,8 +1344,8 @@ typedef struct Tcl_HashSearch { #endif /* - * Macros to use for clients to use to invoke find and create procedures - * for hash tables: + * Macros to use for clients to use to invoke find and create functions for + * hash tables: */ #if TCL_PRESERVE_BINARY_COMPATABILITY @@ -1351,9 +1362,9 @@ typedef struct Tcl_HashSearch { #endif /* TCL_PRESERVE_BINARY_COMPATABILITY */ /* - * Structure definition for information used to keep track of searches - * through dictionaries. These fields should not be accessed by code - * outside tclDictObj.c + * Structure definition for information used to keep track of searches through + * dictionaries. These fields should not be accessed by code outside + * tclDictObj.c */ typedef struct { @@ -1363,11 +1374,11 @@ typedef struct { Tcl_Dict dictionaryPtr; /* Reference to dictionary being searched. */ } Tcl_DictSearch; - /* - * Flag values to pass to Tcl_DoOneEvent to disable searches - * for some kinds of events: + * Flag values to pass to Tcl_DoOneEvent to disable searches for some kinds of + * events: */ + #define TCL_DONT_WAIT (1<<1) #define TCL_WINDOW_EVENTS (1<<2) #define TCL_FILE_EVENTS (1<<3) @@ -1376,22 +1387,23 @@ typedef struct { #define TCL_ALL_EVENTS (~TCL_DONT_WAIT) /* - * The following structure defines a generic event for the Tcl event - * system. These are the things that are queued in calls to Tcl_QueueEvent - * and serviced later by Tcl_DoOneEvent. There can be many different - * kinds of events with different fields, corresponding to window events, - * timer events, etc. The structure for a particular event consists of - * a Tcl_Event header followed by additional information specific to that - * event. + * The following structure defines a generic event for the Tcl event system. + * These are the things that are queued in calls to Tcl_QueueEvent and + * serviced later by Tcl_DoOneEvent. There can be many different kinds of + * events with different fields, corresponding to window events, timer events, + * etc. The structure for a particular event consists of a Tcl_Event header + * followed by additional information specific to that event. */ + struct Tcl_Event { - Tcl_EventProc *proc; /* Procedure to call to service this event. */ + Tcl_EventProc *proc; /* Function to call to service this event. */ struct Tcl_Event *nextPtr; /* Next in list of pending events, or NULL. */ }; /* * Positions to pass to Tcl_QueueEvent: */ + typedef enum { TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, TCL_QUEUE_MARK } Tcl_QueuePosition; @@ -1400,15 +1412,16 @@ typedef enum { * Values to pass to Tcl_SetServiceMode to specify the behavior of notifier * event routines. */ + #define TCL_SERVICE_NONE 0 #define TCL_SERVICE_ALL 1 - /* - * The following structure keeps is used to hold a time value, either as - * an absolute time (the number of seconds from the epoch) or as an - * elapsed time. On Unix systems the epoch is Midnight Jan 1, 1970 GMT. + * The following structure keeps is used to hold a time value, either as an + * absolute time (the number of seconds from the epoch) or as an elapsed time. + * On Unix systems the epoch is Midnight Jan 1, 1970 GMT. */ + typedef struct Tcl_Time { long sec; /* Seconds. */ long usec; /* Microseconds. */ @@ -1417,26 +1430,29 @@ typedef struct Tcl_Time { typedef void (Tcl_SetTimerProc) _ANSI_ARGS_((Tcl_Time *timePtr)); typedef int (Tcl_WaitForEventProc) _ANSI_ARGS_((Tcl_Time *timePtr)); -/* TIP #233 (Virtualized Time) +/* + * TIP #233 (Virtualized Time) */ + typedef void (Tcl_GetTimeProc) _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData clientData)); typedef void (Tcl_ScaleTimeProc) _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData clientData)); - /* - * Bits to pass to Tcl_CreateFileHandler and Tcl_CreateChannelHandler - * to indicate what sorts of events are of interest: + * Bits to pass to Tcl_CreateFileHandler and Tcl_CreateChannelHandler to + * indicate what sorts of events are of interest: */ + #define TCL_READABLE (1<<1) #define TCL_WRITABLE (1<<2) #define TCL_EXCEPTION (1<<3) /* - * Flag values to pass to Tcl_OpenCommandChannel to indicate the - * disposition of the stdio handles. TCL_STDIN, TCL_STDOUT, TCL_STDERR, - * are also used in Tcl_GetStdChannel. + * Flag values to pass to Tcl_OpenCommandChannel to indicate the disposition + * of the stdio handles. TCL_STDIN, TCL_STDOUT, TCL_STDERR, are also used in + * Tcl_GetStdChannel. */ -#define TCL_STDIN (1<<1) + +#define TCL_STDIN (1<<1) #define TCL_STDOUT (1<<2) #define TCL_STDERR (1<<3) #define TCL_ENFORCE_MODE (1<<4) @@ -1445,18 +1461,21 @@ typedef void (Tcl_ScaleTimeProc) _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData cli * Bits passed to Tcl_DriverClose2Proc to indicate which side of a channel * should be closed. */ + #define TCL_CLOSE_READ (1<<1) #define TCL_CLOSE_WRITE (1<<2) /* - * Value to use as the closeProc for a channel that supports the - * close2Proc interface. + * Value to use as the closeProc for a channel that supports the close2Proc + * interface. */ + #define TCL_CLOSE2PROC ((Tcl_DriverCloseProc *)1) /* - * Channel version tag. This was introduced in 8.3.2/8.4. + * Channel version tag. This was introduced in 8.3.2/8.4. */ + #define TCL_CHANNEL_VERSION_1 ((Tcl_ChannelTypeVersion) 0x1) #define TCL_CHANNEL_VERSION_2 ((Tcl_ChannelTypeVersion) 0x2) #define TCL_CHANNEL_VERSION_3 ((Tcl_ChannelTypeVersion) 0x3) @@ -1472,6 +1491,7 @@ typedef void (Tcl_ScaleTimeProc) _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData cli /* * Typedefs for the various operations in a channel type: */ + typedef int (Tcl_DriverBlockModeProc) _ANSI_ARGS_(( ClientData instanceData, int mode)); typedef int (Tcl_DriverCloseProc) _ANSI_ARGS_((ClientData instanceData, @@ -1486,7 +1506,7 @@ typedef int (Tcl_DriverSeekProc) _ANSI_ARGS_((ClientData instanceData, long offset, int mode, int *errorCodePtr)); typedef int (Tcl_DriverSetOptionProc) _ANSI_ARGS_(( ClientData instanceData, Tcl_Interp *interp, - CONST char *optionName, CONST char *value)); + CONST char *optionName, CONST char *value)); typedef int (Tcl_DriverGetOptionProc) _ANSI_ARGS_(( ClientData instanceData, Tcl_Interp *interp, CONST84 char *optionName, Tcl_DString *dsPtr)); @@ -1495,26 +1515,29 @@ typedef void (Tcl_DriverWatchProc) _ANSI_ARGS_(( typedef int (Tcl_DriverGetHandleProc) _ANSI_ARGS_(( ClientData instanceData, int direction, ClientData *handlePtr)); -typedef int (Tcl_DriverFlushProc) _ANSI_ARGS_(( - ClientData instanceData)); +typedef int (Tcl_DriverFlushProc) _ANSI_ARGS_((ClientData instanceData)); typedef int (Tcl_DriverHandlerProc) _ANSI_ARGS_(( ClientData instanceData, int interestMask)); typedef Tcl_WideInt (Tcl_DriverWideSeekProc) _ANSI_ARGS_(( ClientData instanceData, Tcl_WideInt offset, int mode, int *errorCodePtr)); - -/* TIP #218, Channel Thread Actions */ +/* + * TIP #218, Channel Thread Actions + */ typedef void (Tcl_DriverThreadActionProc) _ANSI_ARGS_ (( ClientData instanceData, int action)); -/* TIP #208, File Truncation (etc.) */ +/* + * TIP #208, File Truncation (etc.) + */ typedef int (Tcl_DriverTruncateProc) _ANSI_ARGS_(( ClientData instanceData, Tcl_WideInt length)); /* - * The following declarations either map ckalloc and ckfree to - * malloc and free, or they map them to procedures with all sorts - * of debugging hooks defined in tclCkalloc.c. + * The following declarations either map ckalloc and ckfree to malloc and + * free, or they map them to functions with all sorts of debugging hooks + * defined in tclCkalloc.c. */ + #ifdef TCL_MEM_DEBUG # define ckalloc(x) Tcl_DbCkalloc(x, __FILE__, __LINE__) @@ -1522,14 +1545,15 @@ typedef int (Tcl_DriverTruncateProc) _ANSI_ARGS_(( # define ckrealloc(x,y) Tcl_DbCkrealloc((x), (y),__FILE__, __LINE__) # define attemptckalloc(x) Tcl_AttemptDbCkalloc(x, __FILE__, __LINE__) # define attemptckrealloc(x,y) Tcl_AttemptDbCkrealloc((x), (y), __FILE__, __LINE__) + #else /* !TCL_MEM_DEBUG */ /* - * If we are not using the debugging allocator, we should call the - * Tcl_Alloc, et al. routines in order to guarantee that every module - * is using the same memory allocator both inside and outside of the - * Tcl library. + * If we are not using the debugging allocator, we should call the Tcl_Alloc, + * et al. routines in order to guarantee that every module is using the same + * memory allocator both inside and outside of the Tcl library. */ + # define ckalloc(x) Tcl_Alloc(x) # define ckfree(x) Tcl_Free(x) # define ckrealloc(x,y) Tcl_Realloc(x,y) @@ -1544,83 +1568,87 @@ typedef int (Tcl_DriverTruncateProc) _ANSI_ARGS_(( /* * struct Tcl_ChannelType: * - * One such structure exists for each type (kind) of channel. - * It collects together in one place all the functions that are - * part of the specific channel type. + * One such structure exists for each type (kind) of channel. It collects + * together in one place all the functions that are part of the specific + * channel type. * - * It is recommend that the Tcl_Channel* functions are used to access - * elements of this structure, instead of direct accessing. + * It is recommend that the Tcl_Channel* functions are used to access elements + * of this structure, instead of direct accessing. */ + typedef struct Tcl_ChannelType { - char *typeName; /* The name of the channel type in Tcl - * commands. This storage is owned by - * channel type. */ - Tcl_ChannelTypeVersion version; /* Version of the channel type. */ - Tcl_DriverCloseProc *closeProc; /* Procedure to call to close the - * channel, or TCL_CLOSE2PROC if the - * close2Proc should be used - * instead. */ - Tcl_DriverInputProc *inputProc; /* Procedure to call for input - * on channel. */ - Tcl_DriverOutputProc *outputProc; /* Procedure to call for output - * on channel. */ - Tcl_DriverSeekProc *seekProc; /* Procedure to call to seek - * on the channel. May be NULL. */ + char *typeName; /* The name of the channel type in Tcl + * commands. This storage is owned by channel + * type. */ + Tcl_ChannelTypeVersion version; + /* Version of the channel type. */ + Tcl_DriverCloseProc *closeProc; + /* Function to call to close the channel, or + * TCL_CLOSE2PROC if the close2Proc should be + * used instead. */ + Tcl_DriverInputProc *inputProc; + /* Function to call for input on channel. */ + Tcl_DriverOutputProc *outputProc; + /* Function to call for output on channel. */ + Tcl_DriverSeekProc *seekProc; + /* Function to call to seek on the channel. + * May be NULL. */ Tcl_DriverSetOptionProc *setOptionProc; - /* Set an option on a channel. */ + /* Set an option on a channel. */ Tcl_DriverGetOptionProc *getOptionProc; - /* Get an option from a channel. */ - Tcl_DriverWatchProc *watchProc; /* Set up the notifier to watch - * for events on this channel. */ + /* Get an option from a channel. */ + Tcl_DriverWatchProc *watchProc; + /* Set up the notifier to watch for events on + * this channel. */ Tcl_DriverGetHandleProc *getHandleProc; - /* Get an OS handle from the channel - * or NULL if not supported. */ - Tcl_DriverClose2Proc *close2Proc; /* Procedure to call to close the - * channel if the device supports - * closing the read & write sides - * independently. */ + /* Get an OS handle from the channel or NULL + * if not supported. */ + Tcl_DriverClose2Proc *close2Proc; + /* Function to call to close the channel if + * the device supports closing the read & + * write sides independently. */ Tcl_DriverBlockModeProc *blockModeProc; - /* Set blocking mode for the - * raw channel. May be NULL. */ + /* Set blocking mode for the raw channel. May + * be NULL. */ /* * Only valid in TCL_CHANNEL_VERSION_2 channels or later */ - Tcl_DriverFlushProc *flushProc; /* Procedure to call to flush a - * channel. May be NULL. */ - Tcl_DriverHandlerProc *handlerProc; /* Procedure to call to handle a - * channel event. This will be passed - * up the stacked channel chain. */ + Tcl_DriverFlushProc *flushProc; + /* Function to call to flush a channel. May be + * NULL. */ + Tcl_DriverHandlerProc *handlerProc; + /* Function to call to handle a channel event. + * This will be passed up the stacked channel + * chain. */ /* * Only valid in TCL_CHANNEL_VERSION_3 channels or later */ Tcl_DriverWideSeekProc *wideSeekProc; - /* Procedure to call to seek - * on the channel which can - * handle 64-bit offsets. May be - * NULL, and must be NULL if - * seekProc is NULL. */ + /* Function to call to seek on the channel + * which can handle 64-bit offsets. May be + * NULL, and must be NULL if seekProc is + * NULL. */ /* * Only valid in TCL_CHANNEL_VERSION_4 channels or later * TIP #218, Channel Thread Actions * TIP #208 (part relating to truncation) */ Tcl_DriverThreadActionProc *threadActionProc; - /* Procedure to call to notify - * the driver of thread specific - * activity for a channel. - * May be NULL. */ + /* Function to call to notify the driver of + * thread specific activity for a channel. May + * be NULL. */ Tcl_DriverTruncateProc *truncateProc; - /* Procedure to call to truncate the - * underlying file to a particular - * length. May be NULL if the channel - * does not support truncation. */ + /* Function to call to truncate the underlying + * file to a particular length. May be NULL if + * the channel does not support truncation. */ } Tcl_ChannelType; /* - * The following flags determine whether the blockModeProc above should - * set the channel into blocking or nonblocking mode. They are passed - * as arguments to the blockModeProc procedure in the above structure. + * The following flags determine whether the blockModeProc above should set + * the channel into blocking or nonblocking mode. They are passed as arguments + * to the blockModeProc function in the above structure. */ + #define TCL_MODE_BLOCKING 0 /* Put channel into blocking mode. */ #define TCL_MODE_NONBLOCKING 1 /* Put channel into nonblocking * mode. */ @@ -1628,31 +1656,29 @@ typedef struct Tcl_ChannelType { /* * Enum for different types of file paths. */ + typedef enum Tcl_PathType { TCL_PATH_ABSOLUTE, TCL_PATH_RELATIVE, TCL_PATH_VOLUME_RELATIVE } Tcl_PathType; - -/* - * The following structure is used to pass glob type data amongst - * the various glob routines and Tcl_FSMatchInDirectory. +/* + * The following structure is used to pass glob type data amongst the various + * glob routines and Tcl_FSMatchInDirectory. */ + typedef struct Tcl_GlobTypeData { - /* Corresponds to bcdpfls as in 'find -t' */ - int type; - /* Corresponds to file permissions */ - int perm; - /* Acceptable mac type */ - Tcl_Obj* macType; - /* Acceptable mac creator */ - Tcl_Obj* macCreator; + int type; /* Corresponds to bcdpfls as in 'find -t' */ + int perm; /* Corresponds to file permissions */ + Tcl_Obj *macType; /* Acceptable mac type */ + Tcl_Obj *macCreator; /* Acceptable mac creator */ } Tcl_GlobTypeData; /* - * type and permission definitions for glob command + * Type and permission definitions for glob command */ + #define TCL_GLOB_TYPE_BLOCK (1<<0) #define TCL_GLOB_TYPE_CHAR (1<<1) #define TCL_GLOB_TYPE_DIR (1<<2) @@ -1669,70 +1695,69 @@ typedef struct Tcl_GlobTypeData { #define TCL_GLOB_PERM_X (1<<4) /* - * Flags for the unload callback procedure + * Flags for the unload callback function */ -#define TCL_UNLOAD_DETACH_FROM_INTERPRETER (1<<0) -#define TCL_UNLOAD_DETACH_FROM_PROCESS (1<<1) + +#define TCL_UNLOAD_DETACH_FROM_INTERPRETER (1<<0) +#define TCL_UNLOAD_DETACH_FROM_PROCESS (1<<1) /* * Typedefs for the various filesystem operations: */ + typedef int (Tcl_FSStatProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, Tcl_StatBuf *buf)); typedef int (Tcl_FSAccessProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, int mode)); -typedef Tcl_Channel (Tcl_FSOpenFileChannelProc) - _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *pathPtr, - int mode, int permissions)); -typedef int (Tcl_FSMatchInDirectoryProc) _ANSI_ARGS_((Tcl_Interp* interp, - Tcl_Obj *result, Tcl_Obj *pathPtr, CONST char *pattern, +typedef Tcl_Channel (Tcl_FSOpenFileChannelProc) _ANSI_ARGS_(( + Tcl_Interp *interp, Tcl_Obj *pathPtr, int mode, int permissions)); +typedef int (Tcl_FSMatchInDirectoryProc) _ANSI_ARGS_((Tcl_Interp* interp, + Tcl_Obj *result, Tcl_Obj *pathPtr, CONST char *pattern, Tcl_GlobTypeData * types)); typedef Tcl_Obj* (Tcl_FSGetCwdProc) _ANSI_ARGS_((Tcl_Interp *interp)); typedef int (Tcl_FSChdirProc) _ANSI_ARGS_((Tcl_Obj *pathPtr)); -typedef int (Tcl_FSLstatProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - Tcl_StatBuf *buf)); +typedef int (Tcl_FSLstatProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, + Tcl_StatBuf *buf)); typedef int (Tcl_FSCreateDirectoryProc) _ANSI_ARGS_((Tcl_Obj *pathPtr)); typedef int (Tcl_FSDeleteFileProc) _ANSI_ARGS_((Tcl_Obj *pathPtr)); typedef int (Tcl_FSCopyDirectoryProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr, - Tcl_Obj *destPathPtr, Tcl_Obj **errorPtr)); + Tcl_Obj *destPathPtr, Tcl_Obj **errorPtr)); typedef int (Tcl_FSCopyFileProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr, - Tcl_Obj *destPathPtr)); + Tcl_Obj *destPathPtr)); typedef int (Tcl_FSRemoveDirectoryProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - int recursive, Tcl_Obj **errorPtr)); + int recursive, Tcl_Obj **errorPtr)); typedef int (Tcl_FSRenameFileProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr, - Tcl_Obj *destPathPtr)); + Tcl_Obj *destPathPtr)); typedef void (Tcl_FSUnloadFileProc) _ANSI_ARGS_((Tcl_LoadHandle loadHandle)); typedef Tcl_Obj* (Tcl_FSListVolumesProc) _ANSI_ARGS_((void)); /* We have to declare the utime structure here. */ struct utimbuf; -typedef int (Tcl_FSUtimeProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - struct utimbuf *tval)); -typedef int (Tcl_FSNormalizePathProc) _ANSI_ARGS_((Tcl_Interp *interp, - Tcl_Obj *pathPtr, int nextCheckpoint)); +typedef int (Tcl_FSUtimeProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, + struct utimbuf *tval)); +typedef int (Tcl_FSNormalizePathProc) _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *pathPtr, int nextCheckpoint)); typedef int (Tcl_FSFileAttrsGetProc) _ANSI_ARGS_((Tcl_Interp *interp, - int index, Tcl_Obj *pathPtr, - Tcl_Obj **objPtrRef)); -typedef CONST char** (Tcl_FSFileAttrStringsProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - Tcl_Obj** objPtrRef)); + int index, Tcl_Obj *pathPtr, Tcl_Obj **objPtrRef)); +typedef CONST char** (Tcl_FSFileAttrStringsProc) _ANSI_ARGS_(( + Tcl_Obj *pathPtr, Tcl_Obj** objPtrRef)); typedef int (Tcl_FSFileAttrsSetProc) _ANSI_ARGS_((Tcl_Interp *interp, - int index, Tcl_Obj *pathPtr, - Tcl_Obj *objPtr)); -typedef Tcl_Obj* (Tcl_FSLinkProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - Tcl_Obj *toPtr, int linkType)); -typedef int (Tcl_FSLoadFileProc) _ANSI_ARGS_((Tcl_Interp * interp, - Tcl_Obj *pathPtr, - Tcl_LoadHandle *handlePtr, - Tcl_FSUnloadFileProc **unloadProcPtr)); -typedef int (Tcl_FSPathInFilesystemProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, - ClientData *clientDataPtr)); -typedef Tcl_Obj* (Tcl_FSFilesystemPathTypeProc) - _ANSI_ARGS_((Tcl_Obj *pathPtr)); -typedef Tcl_Obj* (Tcl_FSFilesystemSeparatorProc) - _ANSI_ARGS_((Tcl_Obj *pathPtr)); + int index, Tcl_Obj *pathPtr, Tcl_Obj *objPtr)); +typedef Tcl_Obj* (Tcl_FSLinkProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, + Tcl_Obj *toPtr, int linkType)); +typedef int (Tcl_FSLoadFileProc) _ANSI_ARGS_((Tcl_Interp * interp, + Tcl_Obj *pathPtr, Tcl_LoadHandle *handlePtr, + Tcl_FSUnloadFileProc **unloadProcPtr)); +typedef int (Tcl_FSPathInFilesystemProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, + ClientData *clientDataPtr)); +typedef Tcl_Obj* (Tcl_FSFilesystemPathTypeProc) _ANSI_ARGS_(( + Tcl_Obj *pathPtr)); +typedef Tcl_Obj* (Tcl_FSFilesystemSeparatorProc) _ANSI_ARGS_(( + Tcl_Obj *pathPtr)); typedef void (Tcl_FSFreeInternalRepProc) _ANSI_ARGS_((ClientData clientData)); -typedef ClientData (Tcl_FSDupInternalRepProc) - _ANSI_ARGS_((ClientData clientData)); -typedef Tcl_Obj* (Tcl_FSInternalToNormalizedProc) - _ANSI_ARGS_((ClientData clientData)); -typedef ClientData (Tcl_FSCreateInternalRepProc) _ANSI_ARGS_((Tcl_Obj *pathPtr)); +typedef ClientData (Tcl_FSDupInternalRepProc) _ANSI_ARGS_(( + ClientData clientData)); +typedef Tcl_Obj* (Tcl_FSInternalToNormalizedProc) _ANSI_ARGS_(( + ClientData clientData)); +typedef ClientData (Tcl_FSCreateInternalRepProc) _ANSI_ARGS_(( + Tcl_Obj *pathPtr)); typedef struct Tcl_FSVersion_ *Tcl_FSVersion; @@ -1750,207 +1775,183 @@ typedef struct Tcl_FSVersion_ *Tcl_FSVersion; /* * struct Tcl_Filesystem: * - * One such structure exists for each type (kind) of filesystem. - * It collects together in one place all the functions that are - * part of the specific filesystem. Tcl always accesses the - * filesystem through one of these structures. - * - * Not all entries need be non-NULL; any which are NULL are simply - * ignored. However, a complete filesystem should provide all of - * these functions. The explanations in the structure show - * the importance of each function. + * One such structure exists for each type (kind) of filesystem. It collects + * together in one place all the functions that are part of the specific + * filesystem. Tcl always accesses the filesystem through one of these + * structures. + * + * Not all entries need be non-NULL; any which are NULL are simply ignored. + * However, a complete filesystem should provide all of these functions. The + * explanations in the structure show the importance of each function. */ typedef struct Tcl_Filesystem { - CONST char *typeName; /* The name of the filesystem. */ - int structureLength; /* Length of this structure, so future - * binary compatibility can be assured. */ - Tcl_FSVersion version; - /* Version of the filesystem type. */ + CONST char *typeName; /* The name of the filesystem. */ + int structureLength; /* Length of this structure, so future binary + * compatibility can be assured. */ + Tcl_FSVersion version; /* Version of the filesystem type. */ Tcl_FSPathInFilesystemProc *pathInFilesystemProc; - /* Function to check whether a path is in - * this filesystem. This is the most - * important filesystem procedure. */ + /* Function to check whether a path is in this + * filesystem. This is the most important + * filesystem function. */ Tcl_FSDupInternalRepProc *dupInternalRepProc; - /* Function to duplicate internal fs rep. May - * be NULL (but then fs is less efficient). */ + /* Function to duplicate internal fs rep. May + * be NULL (but then fs is less efficient). */ Tcl_FSFreeInternalRepProc *freeInternalRepProc; - /* Function to free internal fs rep. Must - * be implemented, if internal representations - * need freeing, otherwise it can be NULL. */ + /* Function to free internal fs rep. Must be + * implemented if internal representations + * need freeing, otherwise it can be NULL. */ Tcl_FSInternalToNormalizedProc *internalToNormalizedProc; - /* Function to convert internal representation - * to a normalized path. Only required if - * the fs creates pure path objects with no - * string/path representation. */ + /* Function to convert internal representation + * to a normalized path. Only required if the + * fs creates pure path objects with no + * string/path representation. */ Tcl_FSCreateInternalRepProc *createInternalRepProc; - /* Function to create a filesystem-specific - * internal representation. May be NULL - * if paths have no internal representation, - * or if the Tcl_FSPathInFilesystemProc - * for this filesystem always immediately - * creates an internal representation for - * paths it accepts. */ - Tcl_FSNormalizePathProc *normalizePathProc; - /* Function to normalize a path. Should - * be implemented for all filesystems - * which can have multiple string - * representations for the same path - * object. */ + /* Function to create a filesystem-specific + * internal representation. May be NULL if + * paths have no internal representation, or + * if the Tcl_FSPathInFilesystemProc for this + * filesystem always immediately creates an + * internal representation for paths it + * accepts. */ + Tcl_FSNormalizePathProc *normalizePathProc; + /* Function to normalize a path. Should be + * implemented for all filesystems which can + * have multiple string representations for + * the same path object. */ Tcl_FSFilesystemPathTypeProc *filesystemPathTypeProc; - /* Function to determine the type of a - * path in this filesystem. May be NULL. */ + /* Function to determine the type of a path in + * this filesystem. May be NULL. */ Tcl_FSFilesystemSeparatorProc *filesystemSeparatorProc; - /* Function to return the separator - * character(s) for this filesystem. Must - * be implemented. */ - Tcl_FSStatProc *statProc; - /* - * Function to process a 'Tcl_FSStat()' - * call. Must be implemented for any - * reasonable filesystem. - */ - Tcl_FSAccessProc *accessProc; - /* - * Function to process a 'Tcl_FSAccess()' - * call. Must be implemented for any - * reasonable filesystem. - */ - Tcl_FSOpenFileChannelProc *openFileChannelProc; - /* - * Function to process a - * 'Tcl_FSOpenFileChannel()' call. Must be - * implemented for any reasonable - * filesystem. - */ - Tcl_FSMatchInDirectoryProc *matchInDirectoryProc; - /* Function to process a - * 'Tcl_FSMatchInDirectory()'. If not - * implemented, then glob and recursive - * copy functionality will be lacking in - * the filesystem. */ - Tcl_FSUtimeProc *utimeProc; - /* Function to process a - * 'Tcl_FSUtime()' call. Required to - * allow setting (not reading) of times - * with 'file mtime', 'file atime' and - * the open-r/open-w/fcopy implementation - * of 'file copy'. */ - Tcl_FSLinkProc *linkProc; - /* Function to process a - * 'Tcl_FSLink()' call. Should be - * implemented only if the filesystem supports - * links (reading or creating). */ + /* Function to return the separator + * character(s) for this filesystem. Must be + * implemented. */ + Tcl_FSStatProc *statProc; /* Function to process a 'Tcl_FSStat()' call. + * Must be implemented for any reasonable + * filesystem. */ + Tcl_FSAccessProc *accessProc; + /* Function to process a 'Tcl_FSAccess()' + * call. Must be implemented for any + * reasonable filesystem. */ + Tcl_FSOpenFileChannelProc *openFileChannelProc; + /* Function to process a + * 'Tcl_FSOpenFileChannel()' call. Must be + * implemented for any reasonable + * filesystem. */ + Tcl_FSMatchInDirectoryProc *matchInDirectoryProc; + /* Function to process a + * 'Tcl_FSMatchInDirectory()'. If not + * implemented, then glob and recursive copy + * functionality will be lacking in the + * filesystem. */ + Tcl_FSUtimeProc *utimeProc; /* Function to process a 'Tcl_FSUtime()' call. + * Required to allow setting (not reading) of + * times with 'file mtime', 'file atime' and + * the open-r/open-w/fcopy implementation of + * 'file copy'. */ + Tcl_FSLinkProc *linkProc; /* Function to process a 'Tcl_FSLink()' call. + * Should be implemented only if the + * filesystem supports links (reading or + * creating). */ Tcl_FSListVolumesProc *listVolumesProc; - /* Function to list any filesystem volumes - * added by this filesystem. Should be - * implemented only if the filesystem adds - * volumes at the head of the filesystem. */ + /* Function to list any filesystem volumes + * added by this filesystem. Should be + * implemented only if the filesystem adds + * volumes at the head of the filesystem. */ Tcl_FSFileAttrStringsProc *fileAttrStringsProc; - /* Function to list all attributes strings - * which are valid for this filesystem. - * If not implemented the filesystem will - * not support the 'file attributes' command. - * This allows arbitrary additional information - * to be attached to files in the filesystem. */ + /* Function to list all attributes strings + * which are valid for this filesystem. If not + * implemented the filesystem will not support + * the 'file attributes' command. This allows + * arbitrary additional information to be + * attached to files in the filesystem. */ Tcl_FSFileAttrsGetProc *fileAttrsGetProc; - /* Function to process a - * 'Tcl_FSFileAttrsGet()' call, used by - * 'file attributes'. */ + /* Function to process a + * 'Tcl_FSFileAttrsGet()' call, used by 'file + * attributes'. */ Tcl_FSFileAttrsSetProc *fileAttrsSetProc; - /* Function to process a - * 'Tcl_FSFileAttrsSet()' call, used by - * 'file attributes'. */ - Tcl_FSCreateDirectoryProc *createDirectoryProc; - /* Function to process a - * 'Tcl_FSCreateDirectory()' call. Should - * be implemented unless the FS is - * read-only. */ - Tcl_FSRemoveDirectoryProc *removeDirectoryProc; - /* Function to process a - * 'Tcl_FSRemoveDirectory()' call. Should - * be implemented unless the FS is - * read-only. */ - Tcl_FSDeleteFileProc *deleteFileProc; - /* Function to process a - * 'Tcl_FSDeleteFile()' call. Should - * be implemented unless the FS is - * read-only. */ - Tcl_FSCopyFileProc *copyFileProc; - /* Function to process a - * 'Tcl_FSCopyFile()' call. If not - * implemented Tcl will fall back - * on open-r, open-w and fcopy as - * a copying mechanism, for copying - * actions initiated in Tcl (not C). */ - Tcl_FSRenameFileProc *renameFileProc; - /* Function to process a - * 'Tcl_FSRenameFile()' call. If not - * implemented, Tcl will fall back on - * a copy and delete mechanism, for - * rename actions initiated in Tcl (not C). */ - Tcl_FSCopyDirectoryProc *copyDirectoryProc; - /* Function to process a - * 'Tcl_FSCopyDirectory()' call. If - * not implemented, Tcl will fall back - * on a recursive create-dir, file copy - * mechanism, for copying actions - * initiated in Tcl (not C). */ - Tcl_FSLstatProc *lstatProc; - /* Function to process a - * 'Tcl_FSLstat()' call. If not implemented, - * Tcl will attempt to use the 'statProc' - * defined above instead. */ - Tcl_FSLoadFileProc *loadFileProc; - /* Function to process a - * 'Tcl_FSLoadFile()' call. If not - * implemented, Tcl will fall back on - * a copy to native-temp followed by a - * Tcl_FSLoadFile on that temporary copy. */ - Tcl_FSGetCwdProc *getCwdProc; - /* - * Function to process a 'Tcl_FSGetCwd()' - * call. Most filesystems need not - * implement this. It will usually only be - * called once, if 'getcwd' is called - * before 'chdir'. May be NULL. - */ - Tcl_FSChdirProc *chdirProc; - /* - * Function to process a 'Tcl_FSChdir()' - * call. If filesystems do not implement - * this, it will be emulated by a series of - * directory access checks. Otherwise, - * virtual filesystems which do implement - * it need only respond with a positive - * return result if the dirName is a valid - * directory in their filesystem. They - * need not remember the result, since that - * will be automatically remembered for use - * by GetCwd. Real filesystems should - * carry out the correct action (i.e. call - * the correct system 'chdir' api). If not - * implemented, then 'cd' and 'pwd' will - * fail inside the filesystem. - */ + /* Function to process a + * 'Tcl_FSFileAttrsSet()' call, used by 'file + * attributes'. */ + Tcl_FSCreateDirectoryProc *createDirectoryProc; + /* Function to process a + * 'Tcl_FSCreateDirectory()' call. Should be + * implemented unless the FS is read-only. */ + Tcl_FSRemoveDirectoryProc *removeDirectoryProc; + /* Function to process a + * 'Tcl_FSRemoveDirectory()' call. Should be + * implemented unless the FS is read-only. */ + Tcl_FSDeleteFileProc *deleteFileProc; + /* Function to process a 'Tcl_FSDeleteFile()' + * call. Should be implemented unless the FS + * is read-only. */ + Tcl_FSCopyFileProc *copyFileProc; + /* Function to process a 'Tcl_FSCopyFile()' + * call. If not implemented Tcl will fall back + * on open-r, open-w and fcopy as a copying + * mechanism, for copying actions initiated in + * Tcl (not C). */ + Tcl_FSRenameFileProc *renameFileProc; + /* Function to process a 'Tcl_FSRenameFile()' + * call. If not implemented, Tcl will fall + * back on a copy and delete mechanism, for + * rename actions initiated in Tcl (not C). */ + Tcl_FSCopyDirectoryProc *copyDirectoryProc; + /* Function to process a + * 'Tcl_FSCopyDirectory()' call. If not + * implemented, Tcl will fall back on a + * recursive create-dir, file copy mechanism, + * for copying actions initiated in Tcl (not + * C). */ + Tcl_FSLstatProc *lstatProc; /* Function to process a 'Tcl_FSLstat()' call. + * If not implemented, Tcl will attempt to use + * the 'statProc' defined above instead. */ + Tcl_FSLoadFileProc *loadFileProc; + /* Function to process a 'Tcl_FSLoadFile()' + * call. If not implemented, Tcl will fall + * back on a copy to native-temp followed by a + * Tcl_FSLoadFile on that temporary copy. */ + Tcl_FSGetCwdProc *getCwdProc; + /* Function to process a 'Tcl_FSGetCwd()' + * call. Most filesystems need not implement + * this. It will usually only be called once, + * if 'getcwd' is called before 'chdir'. May + * be NULL. */ + Tcl_FSChdirProc *chdirProc; /* Function to process a 'Tcl_FSChdir()' call. + * If filesystems do not implement this, it + * will be emulated by a series of directory + * access checks. Otherwise, virtual + * filesystems which do implement it need only + * respond with a positive return result if + * the dirName is a valid directory in their + * filesystem. They need not remember the + * result, since that will be automatically + * remembered for use by GetCwd. Real + * filesystems should carry out the correct + * action (i.e. call the correct system + * 'chdir' api). If not implemented, then 'cd' + * and 'pwd' will fail inside the + * filesystem. */ } Tcl_Filesystem; /* - * The following definitions are used as values for the 'linkAction' flag - * to Tcl_FSLink, or the linkProc of any filesystem. Any combination - * of flags can be given. For link creation, the linkProc should create - * a link which matches any of the types given. - * - * TCL_CREATE_SYMBOLIC_LINK: Create a symbolic or soft link. - * TCL_CREATE_HARD_LINK: Create a hard link. + * The following definitions are used as values for the 'linkAction' flag to + * Tcl_FSLink, or the linkProc of any filesystem. Any combination of flags can + * be given. For link creation, the linkProc should create a link which + * matches any of the types given. + * + * TCL_CREATE_SYMBOLIC_LINK - Create a symbolic or soft link. + * TCL_CREATE_HARD_LINK - Create a hard link. */ -#define TCL_CREATE_SYMBOLIC_LINK 0x01 -#define TCL_CREATE_HARD_LINK 0x02 + +#define TCL_CREATE_SYMBOLIC_LINK 0x01 +#define TCL_CREATE_HARD_LINK 0x02 /* - * The following structure represents the Notifier functions that - * you can override with the Tcl_SetNotifier call. + * The following structure represents the Notifier functions that you can + * override with the Tcl_SetNotifier call. */ + typedef struct Tcl_NotifierProcs { Tcl_SetTimerProc *setTimerProc; Tcl_WaitForEventProc *waitForEventProc; @@ -1962,169 +1963,160 @@ typedef struct Tcl_NotifierProcs { Tcl_ServiceModeHookProc *serviceModeHookProc; } Tcl_NotifierProcs; - /* - * The following structure represents a user-defined encoding. It collects + * The following structure represents a user-defined encoding. It collects * together all the functions that are used by the specific encoding. */ + typedef struct Tcl_EncodingType { - CONST char *encodingName; /* The name of the encoding, e.g. "euc-jp". + CONST char *encodingName; /* The name of the encoding, e.g. "euc-jp". * This name is the unique key for this * encoding type. */ Tcl_EncodingConvertProc *toUtfProc; - /* Procedure to convert from external - * encoding into UTF-8. */ + /* Function to convert from external encoding + * into UTF-8. */ Tcl_EncodingConvertProc *fromUtfProc; - /* Procedure to convert from UTF-8 into + /* Function to convert from UTF-8 into * external encoding. */ Tcl_EncodingFreeProc *freeProc; - /* If non-NULL, procedure to call when this + /* If non-NULL, function to call when this * encoding is deleted. */ ClientData clientData; /* Arbitrary value associated with encoding - * type. Passed to conversion procedures. */ + * type. Passed to conversion functions. */ int nullSize; /* Number of zero bytes that signify - * end-of-string in this encoding. This - * number is used to determine the source - * string length when the srcLen argument is - * negative. Must be 1 or 2. */ -} Tcl_EncodingType; + * end-of-string in this encoding. This number + * is used to determine the source string + * length when the srcLen argument is + * negative. Must be 1 or 2. */ +} Tcl_EncodingType; /* * The following definitions are used as values for the conversion control * flags argument when converting text from one character set to another: * - * TCL_ENCODING_START: Signifies that the source buffer is the first + * TCL_ENCODING_START - Signifies that the source buffer is the first * block in a (potentially multi-block) input - * stream. Tells the conversion procedure to - * reset to an initial state and perform any + * stream. Tells the conversion function to reset + * to an initial state and perform any * initialization that needs to occur before the - * first byte is converted. If the source - * buffer contains the entire input stream to be + * first byte is converted. If the source buffer + * contains the entire input stream to be * converted, this flag should be set. - * - * TCL_ENCODING_END: Signifies that the source buffer is the last + * TCL_ENCODING_END - Signifies that the source buffer is the last * block in a (potentially multi-block) input - * stream. Tells the conversion routine to + * stream. Tells the conversion routine to * perform any finalization that needs to occur * after the last byte is converted and then to - * reset to an initial state. If the source + * reset to an initial state. If the source * buffer contains the entire input stream to be * converted, this flag should be set. - * - * TCL_ENCODING_STOPONERROR: If set, then the converter will return - * immediately upon encountering an invalid - * byte sequence or a source character that has - * no mapping in the target encoding. If clear, - * then the converter will skip the problem, - * substituting one or more "close" characters - * in the destination buffer and then continue - * to sonvert the source. + * TCL_ENCODING_STOPONERROR - If set, then the converter will return + * immediately upon encountering an invalid byte + * sequence or a source character that has no + * mapping in the target encoding. If clear, then + * the converter will skip the problem, + * substituting one or more "close" characters in + * the destination buffer and then continue to + * convert the source. */ + #define TCL_ENCODING_START 0x01 #define TCL_ENCODING_END 0x02 #define TCL_ENCODING_STOPONERROR 0x04 - /* - * The following data structures and declarations are for the new Tcl - * parser. + * The following data structures and declarations are for the new Tcl parser. */ /* - * For each word of a command, and for each piece of a word such as a - * variable reference, one of the following structures is created to - * describe the token. + * For each word of a command, and for each piece of a word such as a variable + * reference, one of the following structures is created to describe the + * token. */ + typedef struct Tcl_Token { - int type; /* Type of token, such as TCL_TOKEN_WORD; - * see below for valid types. */ + int type; /* Type of token, such as TCL_TOKEN_WORD; see + * below for valid types. */ CONST char *start; /* First character in token. */ int size; /* Number of bytes in token. */ - int numComponents; /* If this token is composed of other - * tokens, this field tells how many of - * them there are (including components of - * components, etc.). The component tokens - * immediately follow this one. */ + int numComponents; /* If this token is composed of other tokens, + * this field tells how many of them there are + * (including components of components, etc.). + * The component tokens immediately follow + * this one. */ } Tcl_Token; /* - * Type values defined for Tcl_Token structures. These values are - * defined as mask bits so that it's easy to check for collections of - * types. + * Type values defined for Tcl_Token structures. These values are defined as + * mask bits so that it's easy to check for collections of types. * * TCL_TOKEN_WORD - The token describes one word of a command, - * from the first non-blank character of - * the word (which may be " or {) up to but - * not including the space, semicolon, or - * bracket that terminates the word. - * NumComponents counts the total number of - * sub-tokens that make up the word. This - * includes, for example, sub-tokens of - * TCL_TOKEN_VARIABLE tokens. - * TCL_TOKEN_SIMPLE_WORD - This token is just like TCL_TOKEN_WORD - * except that the word is guaranteed to - * consist of a single TCL_TOKEN_TEXT - * sub-token. - * TCL_TOKEN_TEXT - The token describes a range of literal - * text that is part of a word. - * NumComponents is always 0. - * TCL_TOKEN_BS - The token describes a backslash sequence - * that must be collapsed. NumComponents - * is always 0. + * from the first non-blank character of the word + * (which may be " or {) up to but not including + * the space, semicolon, or bracket that + * terminates the word. NumComponents counts the + * total number of sub-tokens that make up the + * word. This includes, for example, sub-tokens + * of TCL_TOKEN_VARIABLE tokens. + * TCL_TOKEN_SIMPLE_WORD - This token is just like TCL_TOKEN_WORD except + * that the word is guaranteed to consist of a + * single TCL_TOKEN_TEXT sub-token. + * TCL_TOKEN_TEXT - The token describes a range of literal text + * that is part of a word. NumComponents is + * always 0. + * TCL_TOKEN_BS - The token describes a backslash sequence that + * must be collapsed. NumComponents is always 0. * TCL_TOKEN_COMMAND - The token describes a command whose result - * must be substituted into the word. The - * token includes the enclosing brackets. - * NumComponents is always 0. - * TCL_TOKEN_VARIABLE - The token describes a variable - * substitution, including the dollar sign, - * variable name, and array index (if there - * is one) up through the right - * parentheses. NumComponents tells how - * many additional tokens follow to - * represent the variable name. The first - * token will be a TCL_TOKEN_TEXT token - * that describes the variable name. If - * the variable is an array reference then - * there will be one or more additional - * tokens, of type TCL_TOKEN_TEXT, + * must be substituted into the word. The token + * includes the enclosing brackets. NumComponents + * is always 0. + * TCL_TOKEN_VARIABLE - The token describes a variable substitution, + * including the dollar sign, variable name, and + * array index (if there is one) up through the + * right parentheses. NumComponents tells how + * many additional tokens follow to represent the + * variable name. The first token will be a + * TCL_TOKEN_TEXT token that describes the + * variable name. If the variable is an array + * reference then there will be one or more + * additional tokens, of type TCL_TOKEN_TEXT, * TCL_TOKEN_BS, TCL_TOKEN_COMMAND, and - * TCL_TOKEN_VARIABLE, that describe the - * array index; numComponents counts the - * total number of nested tokens that make - * up the variable reference, including - * sub-tokens of TCL_TOKEN_VARIABLE tokens. - * TCL_TOKEN_SUB_EXPR - The token describes one subexpression of a - * expression, from the first non-blank - * character of the subexpression up to but not - * including the space, brace, or bracket - * that terminates the subexpression. - * NumComponents counts the total number of - * following subtokens that make up the - * subexpression; this includes all subtokens - * for any nested TCL_TOKEN_SUB_EXPR tokens. - * For example, a numeric value used as a + * TCL_TOKEN_VARIABLE, that describe the array + * index; numComponents counts the total number + * of nested tokens that make up the variable + * reference, including sub-tokens of + * TCL_TOKEN_VARIABLE tokens. + * TCL_TOKEN_SUB_EXPR - The token describes one subexpression of an + * expression, from the first non-blank character + * of the subexpression up to but not including + * the space, brace, or bracket that terminates + * the subexpression. NumComponents counts the + * total number of following subtokens that make + * up the subexpression; this includes all + * subtokens for any nested TCL_TOKEN_SUB_EXPR + * tokens. For example, a numeric value used as a * primitive operand is described by a * TCL_TOKEN_SUB_EXPR token followed by a * TCL_TOKEN_TEXT token. A binary subexpression * is described by a TCL_TOKEN_SUB_EXPR token - * followed by the TCL_TOKEN_OPERATOR token - * for the operator, then TCL_TOKEN_SUB_EXPR - * tokens for the left then the right operands. + * followed by the TCL_TOKEN_OPERATOR token for + * the operator, then TCL_TOKEN_SUB_EXPR tokens + * for the left then the right operands. * TCL_TOKEN_OPERATOR - The token describes one expression operator. * An operator might be the name of a math * function such as "abs". A TCL_TOKEN_OPERATOR * token is always preceeded by one * TCL_TOKEN_SUB_EXPR token for the operator's - * subexpression, and is followed by zero or - * more TCL_TOKEN_SUB_EXPR tokens for the - * operator's operands. NumComponents is - * always 0. - * TCL_TOKEN_EXPAND_WORD - This token is just like TCL_TOKEN_WORD - * except that it marks a word that began with - * the literal character prefix "{expand}". This - * word is marked to be expanded - that is, broken + * subexpression, and is followed by zero or more + * TCL_TOKEN_SUB_EXPR tokens for the operator's + * operands. NumComponents is always 0. + * TCL_TOKEN_EXPAND_WORD - This token is just like TCL_TOKEN_WORD except + * that it marks a word that began with the + * literal character prefix "{expand}". This word + * is marked to be expanded - that is, broken * into words after substitution is complete. */ + #define TCL_TOKEN_WORD 1 #define TCL_TOKEN_SIMPLE_WORD 2 #define TCL_TOKEN_TEXT 4 @@ -2136,10 +2128,10 @@ typedef struct Tcl_Token { #define TCL_TOKEN_EXPAND_WORD 256 /* - * Parsing error types. On any parsing error, one of these values - * will be stored in the error field of the Tcl_Parse structure - * defined below. + * Parsing error types. On any parsing error, one of these values will be + * stored in the error field of the Tcl_Parse structure defined below. */ + #define TCL_PARSE_SUCCESS 0 #define TCL_PARSE_QUOTE_EXTRA 1 #define TCL_PARSE_BRACE_EXTRA 2 @@ -2152,31 +2144,32 @@ typedef struct Tcl_Token { #define TCL_PARSE_BAD_NUMBER 9 /* - * A structure of the following type is filled in by Tcl_ParseCommand. - * It describes a single command parsed from an input string. + * A structure of the following type is filled in by Tcl_ParseCommand. It + * describes a single command parsed from an input string. */ + #define NUM_STATIC_TOKENS 20 typedef struct Tcl_Parse { - CONST char *commentStart; /* Pointer to # that begins the first of - * one or more comments preceding the - * command. */ + CONST char *commentStart; /* Pointer to # that begins the first of one + * or more comments preceding the command. */ int commentSize; /* Number of bytes in comments (up through - * newline character that terminates the - * last comment). If there were no - * comments, this field is 0. */ - CONST char *commandStart; /* First character in first word of command. */ - int commandSize; /* Number of bytes in command, including - * first character of first word, up - * through the terminating newline, - * close bracket, or semicolon. */ - int numWords; /* Total number of words in command. May - * be 0. */ - Tcl_Token *tokenPtr; /* Pointer to first token representing - * the words of the command. Initially - * points to staticTokens, but may change - * to point to malloc-ed space if command - * exceeds space in staticTokens. */ + * newline character that terminates the last + * comment). If there were no comments, this + * field is 0. */ + CONST char *commandStart; /* First character in first word of + * command. */ + int commandSize; /* Number of bytes in command, including first + * character of first word, up through the + * terminating newline, close bracket, or + * semicolon. */ + int numWords; /* Total number of words in command. May be + * 0. */ + Tcl_Token *tokenPtr; /* Pointer to first token representing the + * words of the command. Initially points to + * staticTokens, but may change to point to + * malloc-ed space if command exceeds space in + * staticTokens. */ int numTokens; /* Total number of tokens in command. */ int tokensAvailable; /* Total number of tokens available at * *tokenPtr. */ @@ -2184,130 +2177,126 @@ typedef struct Tcl_Parse { * above. */ /* - * The fields below are intended only for the private use of the - * parser. They should not be used by procedures that invoke - * Tcl_ParseCommand. + * The fields below are intended only for the private use of the parser. + * They should not be used by functions that invoke Tcl_ParseCommand. */ CONST char *string; /* The original command string passed to * Tcl_ParseCommand. */ - CONST char *end; /* Points to the character just after the - * last one in the command string. */ - Tcl_Interp *interp; /* Interpreter to use for error reporting, - * or NULL. */ + CONST char *end; /* Points to the character just after the last + * one in the command string. */ + Tcl_Interp *interp; /* Interpreter to use for error reporting, or + * NULL. */ CONST char *term; /* Points to character in string that - * terminated most recent token. Filled in - * by ParseTokens. If an error occurs, - * points to beginning of region where the - * error occurred (e.g. the open brace if - * the close brace is missing). */ + * terminated most recent token. Filled in by + * ParseTokens. If an error occurs, points to + * beginning of region where the error + * occurred (e.g. the open brace if the close + * brace is missing). */ int incomplete; /* This field is set to 1 by Tcl_ParseCommand * if the command appears to be incomplete. * This information is used by * Tcl_CommandComplete. */ Tcl_Token staticTokens[NUM_STATIC_TOKENS]; - /* Initial space for tokens for command. - * This space should be large enough to - * accommodate most commands; dynamic - * space is allocated for very large - * commands that don't fit here. */ + /* Initial space for tokens for command. This + * space should be large enough to accommodate + * most commands; dynamic space is allocated + * for very large commands that don't fit + * here. */ } Tcl_Parse; /* * The following definitions are the error codes returned by the conversion * routines: * - * TCL_OK: All characters were converted. - * - * TCL_CONVERT_NOSPACE: The output buffer would not have been large + * TCL_OK - All characters were converted. + * TCL_CONVERT_NOSPACE - The output buffer would not have been large * enough for all of the converted data; as many * characters as could fit were converted though. - * - * TCL_CONVERT_MULTIBYTE: The last few bytes in the source string were + * TCL_CONVERT_MULTIBYTE - The last few bytes in the source string were * the beginning of a multibyte sequence, but * more bytes were needed to complete this - * sequence. A subsequent call to the conversion + * sequence. A subsequent call to the conversion * routine should pass the beginning of this * unconverted sequence plus additional bytes - * from the source stream to properly convert - * the formerly split-up multibyte sequence. - * - * TCL_CONVERT_SYNTAX: The source stream contained an invalid - * character sequence. This may occur if the + * from the source stream to properly convert the + * formerly split-up multibyte sequence. + * TCL_CONVERT_SYNTAX - The source stream contained an invalid + * character sequence. This may occur if the * input stream has been damaged or if the input - * encoding method was misidentified. This error + * encoding method was misidentified. This error * is reported only if TCL_ENCODING_STOPONERROR * was specified. - * - * TCL_CONVERT_UNKNOWN: The source string contained a character - * that could not be represented in the target - * encoding. This error is reported only if + * TCL_CONVERT_UNKNOWN - The source string contained a character that + * could not be represented in the target + * encoding. This error is reported only if * TCL_ENCODING_STOPONERROR was specified. */ -#define TCL_CONVERT_MULTIBYTE -1 -#define TCL_CONVERT_SYNTAX -2 -#define TCL_CONVERT_UNKNOWN -3 -#define TCL_CONVERT_NOSPACE -4 +#define TCL_CONVERT_MULTIBYTE -1 +#define TCL_CONVERT_SYNTAX -2 +#define TCL_CONVERT_UNKNOWN -3 +#define TCL_CONVERT_NOSPACE -4 /* * The maximum number of bytes that are necessary to represent a single - * Unicode character in UTF-8. The valid values should be 3 or 6 (or - * perhaps 1 if we want to support a non-unicode enabled core). - * If 3, then Tcl_UniChar must be 2-bytes in size (UCS-2). (default) - * If 6, then Tcl_UniChar must be 4-bytes in size (UCS-4). - * At this time UCS-2 mode is the default and recommended mode. - * UCS-4 is experimental and not recommended. It works for the core, - * but most extensions expect UCS-2. + * Unicode character in UTF-8. The valid values should be 3 or 6 (or perhaps 1 + * if we want to support a non-unicode enabled core). If 3, then Tcl_UniChar + * must be 2-bytes in size (UCS-2) (the default). If 6, then Tcl_UniChar must + * be 4-bytes in size (UCS-4). At this time UCS-2 mode is the default and + * recommended mode. UCS-4 is experimental and not recommended. It works for + * the core, but most extensions expect UCS-2. */ + #ifndef TCL_UTF_MAX #define TCL_UTF_MAX 3 #endif /* - * This represents a Unicode character. Any changes to this should - * also be reflected in regcustom.h. + * This represents a Unicode character. Any changes to this should also be + * reflected in regcustom.h. */ + #if TCL_UTF_MAX > 3 /* - * unsigned int isn't 100% accurate as it should be a strict 4-byte - * value (perhaps wchar_t). 64-bit systems may have troubles. The - * size of this value must be reflected correctly in regcustom.h. + * unsigned int isn't 100% accurate as it should be a strict 4-byte value + * (perhaps wchar_t). 64-bit systems may have troubles. The size of this + * value must be reflected correctly in regcustom.h. */ typedef unsigned int Tcl_UniChar; #else typedef unsigned short Tcl_UniChar; #endif -/* TIP #59: The following structure is used in calls - * 'Tcl_RegisterConfig' to provide the system with the embedded - * configuration data. +/* + * TIP #59: The following structure is used in calls 'Tcl_RegisterConfig' to + * provide the system with the embedded configuration data. */ typedef struct Tcl_Config { - CONST char* key; /* Configuration key to register. ASCII encoded, thus UTF-8 */ - CONST char* value; /* The value associated with the key. System encoding */ + CONST char *key; /* Configuration key to register. ASCII + * encoded, thus UTF-8 */ + CONST char *value; /* The value associated with the key. System + * encoding */ } Tcl_Config; - /* * Flags for TIP#143 limits, detailing which limits are active in an - * interpreter. Used for Tcl_{Add,Remove}LimitHandler type argument. + * interpreter. Used for Tcl_{Add,Remove}LimitHandler type argument. */ #define TCL_LIMIT_COMMANDS 0x01 #define TCL_LIMIT_TIME 0x02 /* - * Structure containing information about a limit handler to be called - * when a command- or time-limit is exceeded by an interpreter. + * Structure containing information about a limit handler to be called when a + * command- or time-limit is exceeded by an interpreter. */ typedef void (Tcl_LimitHandlerProc) _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp)); typedef void (Tcl_LimitHandlerDeleteProc) _ANSI_ARGS_((ClientData clientData)); - #ifndef MP_INT_DECLARED typedef struct mp_int mp_int; #define MP_INT_DECLARED @@ -2318,9 +2307,8 @@ typedef unsigned long mp_digit; #endif #ifndef TCL_NO_DEPRECATED - /* - * Deprecated Tcl procedures: + * Deprecated Tcl functions: */ # define Tcl_EvalObj(interp,objPtr) \ @@ -2329,23 +2317,22 @@ typedef unsigned long mp_digit; Tcl_EvalObjEx((interp),(objPtr),TCL_EVAL_GLOBAL) /* - * These function have been renamed. The old names are deprecated, - * but we define these macros for backwards compatibilty. + * These function have been renamed. The old names are deprecated, but we + * define these macros for backwards compatibilty. */ -# define Tcl_Ckalloc Tcl_Alloc -# define Tcl_Ckfree Tcl_Free -# define Tcl_Ckrealloc Tcl_Realloc -# define Tcl_Return Tcl_SetResult -# define Tcl_TildeSubst Tcl_TranslateFileName -# define panic Tcl_Panic -# define panicVA Tcl_PanicVA +# define Tcl_Ckalloc Tcl_Alloc +# define Tcl_Ckfree Tcl_Free +# define Tcl_Ckrealloc Tcl_Realloc +# define Tcl_Return Tcl_SetResult +# define Tcl_TildeSubst Tcl_TranslateFileName +# define panic Tcl_Panic +# define panicVA Tcl_PanicVA #endif - /* - * The following constant is used to test for older versions of Tcl - * in the stubs tables. + * The following constant is used to test for older versions of Tcl in the + * stubs tables. * * Jan Nijtman's plus patch uses 0xFCA1BACF, so we need to pick a different * value since the stubs tables don't match. @@ -2355,10 +2342,9 @@ typedef unsigned long mp_digit; /* * The following function is required to be defined in all stubs aware - * extensions. The function is actually implemented in the stub - * library, not the main Tcl library, although there is a trivial - * implementation in the main library in case an extension is statically - * linked into an application. + * extensions. The function is actually implemented in the stub library, not + * the main Tcl library, although there is a trivial implementation in the + * main library in case an extension is statically linked into an application. */ EXTERN CONST char * Tcl_InitStubs _ANSI_ARGS_((Tcl_Interp *interp, @@ -2382,26 +2368,26 @@ EXTERN CONST char * Tcl_InitStubs _ANSI_ARGS_((Tcl_Interp *interp, EXTERN void Tcl_Main _ANSI_ARGS_((int argc, char **argv, Tcl_AppInitProc *appInitProc)); - /* - * Include the public function declarations that are accessible via - * the stubs table. + * Include the public function declarations that are accessible via the stubs + * table. */ #include "tclDecls.h" /* - * Include platform specific public function declarations that are - * accessible via the stubs table. + * Include platform specific public function declarations that are accessible + * via the stubs table. */ #include "tclPlatDecls.h" /* - * Convenience declaration of Tcl_AppInit for backwards compatibility. - * This function is not *implemented* by the tcl library, so the storage - * class is neither DLLEXPORT nor DLLIMPORT + * Convenience declaration of Tcl_AppInit for backwards compatibility. This + * function is not *implemented* by the tcl library, so the storage class is + * neither DLLEXPORT nor DLLIMPORT. */ + #undef TCL_STORAGE_CLASS #define TCL_STORAGE_CLASS @@ -2413,10 +2399,19 @@ EXTERN int Tcl_AppInit _ANSI_ARGS_((Tcl_Interp *interp)); #endif /* RC_INVOKED */ /* - * * end block for C++ - * */ + * end block for C++ + */ + #ifdef __cplusplus } #endif #endif /* _TCL */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 1f1d34d..f72bbd6 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -2,18 +2,18 @@ * tclBasic.c -- * * Contains the basic facilities for TCL command interpretation, - * including interpreter creation and deletion, command creation - * and deletion, and command/script execution. + * including interpreter creation and deletion, command creation and + * deletion, and command/script execution. * * Copyright (c) 1987-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 1998-1999 by Scriptics Corporation. * Copyright (c) 2001, 2002 by Kevin B. Kenny. All rights reserved. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclBasic.c,v 1.136.2.32 2005/08/30 15:54:29 dgp Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.136.2.33 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -38,59 +38,57 @@ typedef struct OldMathFuncData { * Static procedures in this file: */ -static char * CallCommandTraces _ANSI_ARGS_((Interp *iPtr, Command *cmdPtr, - CONST char *oldName, CONST char* newName, int flags)); -static int CheckDoubleResult _ANSI_ARGS_((Tcl_Interp *interp, - double dResult)); -static void DeleteInterpProc _ANSI_ARGS_((Tcl_Interp *interp)); -static void ProcessUnexpectedResult _ANSI_ARGS_((Tcl_Interp *interp, - int returnCode)); - -static int OldMathFuncProc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); - -static void OldMathFuncDeleteProc _ANSI_ARGS_((ClientData)); - -static int ExprAbsFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprBinaryFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprBoolFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprCeilFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprDoubleFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprEntierFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprFloorFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprIntFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprRandFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprRoundFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprSqrtFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprSrandFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprUnaryFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); -static int ExprWideFunc _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, Tcl_Obj *CONST *objv)); +static char * CallCommandTraces (Interp *iPtr, Command *cmdPtr, + CONST char *oldName, CONST char* newName, int flags); +static int CheckDoubleResult (Tcl_Interp *interp, double dResult); +static void DeleteInterpProc (Tcl_Interp *interp); +static void ProcessUnexpectedResult (Tcl_Interp *interp, int returnCode); + +static int OldMathFuncProc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); + +static void OldMathFuncDeleteProc (ClientData clientData); + +static int ExprAbsFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprBinaryFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprBoolFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprCeilFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprDoubleFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprEntierFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprFloorFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprIntFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprRandFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprRoundFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprSqrtFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprSrandFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprUnaryFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); +static int ExprWideFunc (ClientData clientData, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST *objv); #if 0 -static int VerifyExprObjType _ANSI_ARGS_((Tcl_Interp *interp, - Tcl_Obj *objPtr)); +static int VerifyExprObjType (Tcl_Interp *interp, Tcl_Obj *objPtr); #endif -static void MathFuncWrongNumArgs _ANSI_ARGS_((Tcl_Interp* interp, - int expected, int actual, Tcl_Obj *CONST *objv)); +static void MathFuncWrongNumArgs (Tcl_Interp* interp, int expected, + int actual, Tcl_Obj *CONST *objv); #if 0 #ifndef TCL_WIDE_INT_IS_LONG /* * Extract a double value from a general numeric object. */ + #define GET_DOUBLE_VALUE(doubleVar, objPtr, typePtr) \ if ((typePtr) == &tclIntType) { \ (doubleVar) = (double) (objPtr)->internalRep.longValue; \ @@ -132,9 +130,9 @@ typedef struct { char *name; /* Name of object-based command. */ Tcl_ObjCmdProc *objProc; /* Object-based procedure for command. */ CompileProc *compileProc; /* Procedure called to compile command. */ - int isSafe; /* If non-zero, command will be present - * in safe interpreter. Otherwise it will - * be hidden. */ + int isSafe; /* If non-zero, command will be present in + * safe interpreter. Otherwise it will be + * hidden. */ } CmdInfo; /* @@ -143,7 +141,7 @@ typedef struct { static CmdInfo builtInCmds[] = { /* - * Commands in the generic core. + * Commands in the generic core. */ {"append", Tcl_AppendObjCmd, TclCompileAppendCmd, 1}, @@ -286,13 +284,12 @@ static BuiltinFuncDef BuiltinFuncTable[] = { * Create a new TCL command interpreter. * * Results: - * The return value is a token for the interpreter, which may be - * used in calls to procedures like Tcl_CreateCmd, Tcl_Eval, or - * Tcl_DeleteInterp. + * The return value is a token for the interpreter, which may be used in + * calls to procedures like Tcl_CreateCmd, Tcl_Eval, or Tcl_DeleteInterp. * * Side effects: - * The command interpreter is initialized with the built-in commands - * and with the variables documented in tclvars(n). + * The command interpreter is initialized with the built-in commands and + * with the variables documented in tclvars(n). * *---------------------------------------------------------------------- */ @@ -318,9 +315,9 @@ Tcl_CreateInterp() TclInitSubsystems(); /* - * Panic if someone updated the CallFrame structure without - * also updating the Tcl_CallFrame structure (or vice versa). - */ + * Panic if someone updated the CallFrame structure without also updating + * the Tcl_CallFrame structure (or vice versa). + */ if (sizeof(Tcl_CallFrame) != sizeof(CallFrame)) { /*NOTREACHED*/ @@ -329,8 +326,8 @@ Tcl_CreateInterp() /* * Initialize support for namespaces and create the global namespace - * (whose name is ""; an alias is "::"). This also initializes the - * Tcl object type table and other object management code. + * (whose name is ""; an alias is "::"). This also initializes the Tcl + * object type table and other object management code. */ iPtr = (Interp *) ckalloc(sizeof(Interp)); @@ -386,7 +383,7 @@ Tcl_CreateInterp() Tcl_IncrRefCount(iPtr->emptyObjPtr); iPtr->resultSpace[0] = 0; - iPtr->globalNsPtr = NULL; /* force creation of global ns below */ + iPtr->globalNsPtr = NULL; /* force creation of global ns below */ iPtr->globalNsPtr = (Namespace *) Tcl_CreateNamespace(interp, "", (ClientData) NULL, (Tcl_NamespaceDeleteProc *) NULL); if (iPtr->globalNsPtr == NULL) { @@ -402,7 +399,10 @@ Tcl_CreateInterp() iPtr->execEnvPtr = TclCreateExecEnv(interp); - /* TIP #219, Tcl Channel Reflection API */ + /* + * TIP #219, Tcl Channel Reflection API support. + */ + iPtr->chanMsg = NULL; /* @@ -438,7 +438,7 @@ Tcl_CreateInterp() statsPtr->totalLitStringBytes = 0.0; statsPtr->currentLitStringBytes = 0.0; (VOID *) memset(statsPtr->literalCount, 0, sizeof(statsPtr->literalCount)); -#endif /* TCL_COMPILE_STATS */ +#endif /* TCL_COMPILE_STATS */ /* * Initialise the stub table pointer. @@ -462,13 +462,13 @@ Tcl_CreateInterp() /* * Create the core commands. Do it here, rather than calling - * Tcl_CreateCommand, because it's faster (there's no need to check for - * a pre-existing command by the same name). If a command has a - * Tcl_CmdProc but no Tcl_ObjCmdProc, set the Tcl_ObjCmdProc to - * TclInvokeStringCommand. This is an object-based wrapper procedure - * that extracts strings, calls the string procedure, and creates an - * object for the result. Similarly, if a command has a Tcl_ObjCmdProc - * but no Tcl_CmdProc, set the Tcl_CmdProc to TclInvokeObjectCommand. + * Tcl_CreateCommand, because it's faster (there's no need to check for a + * pre-existing command by the same name). If a command has a Tcl_CmdProc + * but no Tcl_ObjCmdProc, set the Tcl_ObjCmdProc to + * TclInvokeStringCommand. This is an object-based wrapper procedure that + * extracts strings, calls the string procedure, and creates an object for + * the result. Similarly, if a command has a Tcl_ObjCmdProc but no + * Tcl_CmdProc, set the Tcl_CmdProc to TclInvokeObjectCommand. */ for (cmdInfoPtr = builtInCmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) { @@ -503,7 +503,7 @@ Tcl_CreateInterp() } /* - * Register the clock commands. These *do* go through + * Register clock and chan subcommands. These *do* go through * Tcl_CreateObjCommand, since they aren't in the global namespace. */ @@ -549,13 +549,18 @@ Tcl_CreateInterp() */ - /* Register the default [interp bgerror] handler. */ + /* + * Register the default [interp bgerror] handler. + */ Tcl_CreateObjCommand(interp, "::tcl::Bgerror", TclDefaultBgErrorHandlerObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL); - /* Register the unsupported encoding search path command */ + /* + * Register the unsupported encoding search path command. + */ + Tcl_CreateObjCommand(interp, "::tcl::unsupported::EncodingDirs", TclEncodingDirsObjCmd, NULL, NULL); @@ -624,15 +629,14 @@ Tcl_CreateInterp() #ifdef TCL_THREADS /* - * The existence of the "threaded" element of the tcl_platform array indicates - * that this particular Tcl shell has been compiled with threads turned on. - * Using "info exists tcl_platform(threaded)" a Tcl script can introspect on the - * interpreter level of thread safety. + * The existence of the "threaded" element of the tcl_platform array + * indicates that this particular Tcl shell has been compiled with threads + * turned on. Using "info exists tcl_platform(threaded)" a Tcl script can + * introspect on the interpreter level of thread safety. */ - Tcl_SetVar2(interp, "tcl_platform", "threaded", "1", - TCL_GLOBAL_ONLY); + Tcl_SetVar2(interp, "tcl_platform", "threaded", "1", TCL_GLOBAL_ONLY); #endif /* @@ -654,8 +658,7 @@ Tcl_CreateInterp() * * TclHideUnsafeCommands -- * - * Hides base commands that are not marked as safe from this - * interpreter. + * Hides base commands that are not marked as safe from this interpreter. * * Results: * TCL_OK if it succeeds, TCL_ERROR else. @@ -688,20 +691,18 @@ TclHideUnsafeCommands(interp) * * Tcl_CallWhenDeleted -- * - * Arrange for a procedure to be called before a given - * interpreter is deleted. The procedure is called as soon - * as Tcl_DeleteInterp is called; if Tcl_CallWhenDeleted is - * called on an interpreter that has already been deleted, - * the procedure will be called when the last Tcl_Release is - * done on the interpreter. + * Arrange for a procedure to be called before a given interpreter is + * deleted. The procedure is called as soon as Tcl_DeleteInterp is + * called; if Tcl_CallWhenDeleted is called on an interpreter that has + * already been deleted, the procedure will be called when the last + * Tcl_Release is done on the interpreter. * * Results: * None. * * Side effects: - * When Tcl_DeleteInterp is invoked to delete interp, - * proc will be invoked. See the manual entry for - * details. + * When Tcl_DeleteInterp is invoked to delete interp, proc will be + * invoked. See the manual entry for details. * *-------------------------------------------------------------- */ @@ -709,8 +710,8 @@ TclHideUnsafeCommands(interp) void Tcl_CallWhenDeleted(interp, proc, clientData) Tcl_Interp *interp; /* Interpreter to watch. */ - Tcl_InterpDeleteProc *proc; /* Procedure to call when interpreter - * is about to be deleted. */ + Tcl_InterpDeleteProc *proc; /* Procedure to call when interpreter is about + * to be deleted. */ ClientData clientData; /* One-word value to pass to proc. */ { Interp *iPtr = (Interp *) interp; @@ -740,17 +741,16 @@ Tcl_CallWhenDeleted(interp, proc, clientData) * * Tcl_DontCallWhenDeleted -- * - * Cancel the arrangement for a procedure to be called when - * a given interpreter is deleted. + * Cancel the arrangement for a procedure to be called when a given + * interpreter is deleted. * * Results: * None. * * Side effects: - * If proc and clientData were previously registered as a - * callback via Tcl_CallWhenDeleted, they are unregistered. - * If they weren't previously registered then nothing - * happens. + * If proc and clientData were previously registered as a callback via + * Tcl_CallWhenDeleted, they are unregistered. If they weren't previously + * registered then nothing happens. * *-------------------------------------------------------------- */ @@ -758,8 +758,8 @@ Tcl_CallWhenDeleted(interp, proc, clientData) void Tcl_DontCallWhenDeleted(interp, proc, clientData) Tcl_Interp *interp; /* Interpreter to watch. */ - Tcl_InterpDeleteProc *proc; /* Procedure to call when interpreter - * is about to be deleted. */ + Tcl_InterpDeleteProc *proc; /* Procedure to call when interpreter is about + * to be deleted. */ ClientData clientData; /* One-word value to pass to proc. */ { Interp *iPtr = (Interp *) interp; @@ -789,9 +789,9 @@ Tcl_DontCallWhenDeleted(interp, proc, clientData) * Tcl_SetAssocData -- * * Creates a named association between user-specified data, a delete - * function and this interpreter. If the association already exists - * the data is overwritten with the new data. The delete function will - * be invoked when the interpreter is deleted. + * function and this interpreter. If the association already exists the + * data is overwritten with the new data. The delete function will be + * invoked when the interpreter is deleted. * * Results: * None. @@ -806,8 +806,8 @@ void Tcl_SetAssocData(interp, name, proc, clientData) Tcl_Interp *interp; /* Interpreter to associate with. */ CONST char *name; /* Name for association. */ - Tcl_InterpDeleteProc *proc; /* Proc to call when interpreter is - * about to be deleted. */ + Tcl_InterpDeleteProc *proc; /* Proc to call when interpreter is about to + * be deleted. */ ClientData clientData; /* One-word value to pass to proc. */ { Interp *iPtr = (Interp *) interp; @@ -836,8 +836,8 @@ Tcl_SetAssocData(interp, name, proc, clientData) * * Tcl_DeleteAssocData -- * - * Deletes a named association of user-specified data with - * the specified interpreter. + * Deletes a named association of user-specified data with the specified + * interpreter. * * Results: * None. @@ -850,8 +850,8 @@ Tcl_SetAssocData(interp, name, proc, clientData) void Tcl_DeleteAssocData(interp, name) - Tcl_Interp *interp; /* Interpreter to associate with. */ - CONST char *name; /* Name of association. */ + Tcl_Interp *interp; /* Interpreter to associate with. */ + CONST char *name; /* Name of association. */ { Interp *iPtr = (Interp *) interp; AssocData *dPtr; @@ -877,8 +877,8 @@ Tcl_DeleteAssocData(interp, name) * * Tcl_GetAssocData -- * - * Returns the client data associated with this name in the - * specified interpreter. + * Returns the client data associated with this name in the specified + * interpreter. * * Results: * The client data in the AssocData record denoted by the named @@ -892,10 +892,11 @@ Tcl_DeleteAssocData(interp, name) ClientData Tcl_GetAssocData(interp, name, procPtr) - Tcl_Interp *interp; /* Interpreter associated with. */ - CONST char *name; /* Name of association. */ - Tcl_InterpDeleteProc **procPtr; /* Pointer to place to store address - * of current deletion callback. */ + Tcl_Interp *interp; /* Interpreter associated with. */ + CONST char *name; /* Name of association. */ + Tcl_InterpDeleteProc **procPtr; + /* Pointer to place to store address of + * current deletion callback. */ { Interp *iPtr = (Interp *) interp; AssocData *dPtr; @@ -920,8 +921,8 @@ Tcl_GetAssocData(interp, name, procPtr) * * Tcl_InterpDeleted -- * - * Returns nonzero if the interpreter has been deleted with a call - * to Tcl_DeleteInterp. + * Returns nonzero if the interpreter has been deleted with a call to + * Tcl_DeleteInterp. * * Results: * Nonzero if the interpreter is deleted, zero otherwise. @@ -944,11 +945,11 @@ Tcl_InterpDeleted(interp) * * Tcl_DeleteInterp -- * - * Ensures that the interpreter will be deleted eventually. If there - * are no Tcl_Preserve calls in effect for this interpreter, it is - * deleted immediately, otherwise the interpreter is deleted when - * the last Tcl_Preserve is matched by a call to Tcl_Release. In either - * case, the procedure runs the currently registered deletion callbacks. + * Ensures that the interpreter will be deleted eventually. If there are + * no Tcl_Preserve calls in effect for this interpreter, it is deleted + * immediately, otherwise the interpreter is deleted when the last + * Tcl_Preserve is matched by a call to Tcl_Release. In either case, the + * procedure runs the currently registered deletion callbacks. * * Results: * None. @@ -964,8 +965,8 @@ Tcl_InterpDeleted(interp) void Tcl_DeleteInterp(interp) - Tcl_Interp *interp; /* Token for command interpreter (returned - * by a previous call to Tcl_CreateInterp). */ + Tcl_Interp *interp; /* Token for command interpreter (returned by + * a previous call to Tcl_CreateInterp). */ { Interp *iPtr = (Interp *) interp; @@ -985,8 +986,8 @@ Tcl_DeleteInterp(interp) iPtr->flags |= DELETED; iPtr->compileEpoch++; - /* TIP #219, Tcl Channel Reflection API. - * Discard a leftover state. + /* + * TIP #219, Tcl Channel Reflection API. Discard a leftover state. */ if (iPtr->chanMsg != NULL) { @@ -1006,25 +1007,25 @@ Tcl_DeleteInterp(interp) * * DeleteInterpProc -- * - * Helper procedure to delete an interpreter. This procedure is - * called when the last call to Tcl_Preserve on this interpreter - * is matched by a call to Tcl_Release. The procedure cleans up - * all resources used in the interpreter and calls all currently - * registered interpreter deletion callbacks. + * Helper procedure to delete an interpreter. This procedure is called + * when the last call to Tcl_Preserve on this interpreter is matched by a + * call to Tcl_Release. The procedure cleans up all resources used in the + * interpreter and calls all currently registered interpreter deletion + * callbacks. * * Results: * None. * * Side effects: - * Whatever the interpreter deletion callbacks do. Frees resources - * used by the interpreter. + * Whatever the interpreter deletion callbacks do. Frees resources used + * by the interpreter. * *---------------------------------------------------------------------- */ static void DeleteInterpProc(interp) - Tcl_Interp *interp; /* Interpreter to delete. */ + Tcl_Interp *interp; /* Interpreter to delete. */ { Interp *iPtr = (Interp *) interp; Tcl_HashEntry *hPtr; @@ -1041,8 +1042,8 @@ DeleteInterpProc(interp) } /* - * The interpreter should already be marked deleted; otherwise how - * did we get here? + * The interpreter should already be marked deleted; otherwise how did we + * get here? */ if (!(iPtr->flags & DELETED)) { @@ -1050,9 +1051,8 @@ DeleteInterpProc(interp) } /* - * Shut down all limit handler callback scripts that call back - * into this interpreter. Then eliminate all limit handlers for - * this interpreter. + * Shut down all limit handler callback scripts that call back into this + * interpreter. Then eliminate all limit handlers for this interpreter. */ TclRemoveScriptLimitCallbacks(interp); @@ -1078,8 +1078,8 @@ DeleteInterpProc(interp) hTablePtr = iPtr->hiddenCmdTablePtr; if (hTablePtr != NULL) { /* - * Non-pernicious deletion. The deletion callbacks will not be - * allowed to create any new hidden or non-hidden commands. + * Non-pernicious deletion. The deletion callbacks will not be allowed + * to create any new hidden or non-hidden commands. * Tcl_DeleteCommandFromToken() will remove the entry from the * hiddenCmdTablePtr. */ @@ -1124,9 +1124,8 @@ DeleteInterpProc(interp) Tcl_DeleteNamespace((Tcl_Namespace *) iPtr->globalNsPtr); /* - * Free up the result *after* deleting variables, since variable - * deletion could have transferred ownership of the result string - * to Tcl. + * Free up the result *after* deleting variables, since variable deletion + * could have transferred ownership of the result string to Tcl. */ Tcl_FreeResult(interp); @@ -1182,16 +1181,16 @@ DeleteInterpProc(interp) * * Tcl_HideCommand -- * - * Makes a command hidden so that it cannot be invoked from within - * an interpreter, only from within an ancestor. + * Makes a command hidden so that it cannot be invoked from within an + * interpreter, only from within an ancestor. * * Results: - * A standard Tcl result; also leaves a message in the interp's result - * if an error occurs. + * A standard Tcl result; also leaves a message in the interp's result if + * an error occurs. * * Side effects: - * Removes a command from the command table and create an entry - * into the hidden command table under the specified token name. + * Removes a command from the command table and create an entry into the + * hidden command table under the specified token name. * *--------------------------------------------------------------------------- */ @@ -1212,8 +1211,8 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) if (iPtr->flags & DELETED) { /* - * The interpreter is being deleted. Do not create any new - * structures, because it is not safe to modify the interpreter. + * The interpreter is being deleted. Do not create any new structures, + * because it is not safe to modify the interpreter. */ return TCL_ERROR; @@ -1221,13 +1220,12 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) /* * Disallow hiding of commands that are currently in a namespace or - * renaming (as part of hiding) into a namespace. - * - * (because the current implementation with a single global table - * and the needed uniqueness of names cause problems with namespaces) + * renaming (as part of hiding) into a namespace (because the current + * implementation with a single global table and the needed uniqueness of + * names cause problems with namespaces). * - * we don't need to check for "::" in cmdName because the real check is - * on the nsPtr below. + * We don't need to check for "::" in cmdName because the real check is on + * the nsPtr below. * * hiddenCmdToken is just a string which is not interpreted in any way. * It may contain :: but the string is not interpreted as a namespace @@ -1236,9 +1234,9 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) * application always uses the same strings it will get consistent * behaviour. * - * But as we currently limit ourselves to the global namespace only - * for the source, in order to avoid potential confusion, - * lets prevent "::" in the token too. --dl + * But as we currently limit ourselves to the global namespace only for + * the source, in order to avoid potential confusion, lets prevent "::" in + * the token too. - dl */ if (strstr(hiddenCmdToken, "::") != NULL) { @@ -1249,9 +1247,9 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) } /* - * Find the command to hide. An error is returned if cmdName can't - * be found. Look up the command only from the global namespace. - * Full path of the command must be given if using namespaces. + * Find the command to hide. An error is returned if cmdName can't be + * found. Look up the command only from the global namespace. Full path of + * the command must be given if using namespaces. */ cmd = Tcl_FindCommand(interp, cmdName, (Tcl_Namespace *) NULL, @@ -1298,9 +1296,8 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) /* * Nb : This code is currently 'like' a rename to a specialy set apart - * name table. Changes here and in TclRenameCommand must - * be kept in synch untill the common parts are actually - * factorized out. + * name table. Changes here and in TclRenameCommand must be kept in synch + * untill the common parts are actually factorized out. */ /* @@ -1316,16 +1313,16 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) } /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just yet; - * next time we need the info will be soon enough. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we need + * the info will be soon enough. */ TclInvalidateNsCmdLookup(cmdPtr->nsPtr); /* - * Now link the hash table entry with the command structure. - * We ensured above that the nsPtr was right. + * Now link the hash table entry with the command structure. We ensured + * above that the nsPtr was right. */ cmdPtr->hPtr = hPtr; @@ -1333,11 +1330,11 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) /* * If the command being hidden has a compile procedure, increment the - * interpreter's compileEpoch to invalidate its compiled code. This - * makes sure that we don't later try to execute old code compiled with - * command-specific (i.e., inline) bytecodes for the now-hidden - * command. This field is checked in Tcl_EvalObj and ObjInterpProc, - * and code whose compilation epoch doesn't match is recompiled. + * interpreter's compileEpoch to invalidate its compiled code. This makes + * sure that we don't later try to execute old code compiled with + * command-specific (i.e., inline) bytecodes for the now-hidden command. + * This field is checked in Tcl_EvalObj and ObjInterpProc, and code whose + * compilation epoch doesn't match is recompiled. */ if (cmdPtr->compileProc != NULL) { @@ -1351,12 +1348,12 @@ Tcl_HideCommand(interp, cmdName, hiddenCmdToken) * * Tcl_ExposeCommand -- * - * Makes a previously hidden command callable from inside the - * interpreter instead of only by its ancestors. + * Makes a previously hidden command callable from inside the interpreter + * instead of only by its ancestors. * * Results: - * A standard Tcl result. If an error occurs, a message is left - * in the interp's result. + * A standard Tcl result. If an error occurs, a message is left in the + * interp's result. * * Side effects: * Moves commands from one hash table to another. @@ -1380,17 +1377,17 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) if (iPtr->flags & DELETED) { /* - * The interpreter is being deleted. Do not create any new - * structures, because it is not safe to modify the interpreter. + * The interpreter is being deleted. Do not create any new structures, + * because it is not safe to modify the interpreter. */ return TCL_ERROR; } /* - * Check that we have a regular name for the command - * (that the user is not trying to do an expose and a rename - * (to another namespace) at the same time) + * Check that we have a regular name for the command (that the user is not + * trying to do an expose and a rename (to another namespace) at the same + * time). */ if (strstr(cmdName, "::") != NULL) { @@ -1416,16 +1413,17 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) cmdPtr = (Command *) Tcl_GetHashValue(hPtr); /* - * Check that we have a true global namespace - * command (enforced by Tcl_HideCommand() but let's double - * check. (If it was not, we would not really know how to - * handle it). + * Check that we have a true global namespace command (enforced by + * Tcl_HideCommand() but let's double check. (If it was not, we would not + * really know how to handle it). */ + if (cmdPtr->nsPtr != iPtr->globalNsPtr) { - /* - * This case is theoritically impossible, - * we might rather Tcl_Panic() than 'nicely' erroring out ? + /* + * This case is theoritically impossible, we might rather Tcl_Panic() + * than 'nicely' erroring out ? */ + Tcl_AppendResult(interp, "trying to expose a non global command name space command", (char *) NULL); @@ -1436,8 +1434,8 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) nsPtr = cmdPtr->nsPtr; /* - * It is an error to overwrite an existing exposed command as a result - * of exposing a previously hidden command. + * It is an error to overwrite an existing exposed command as a result of + * exposing a previously hidden command. */ hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, cmdName, &new); @@ -1448,9 +1446,9 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) } /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just yet; - * next time we need the info will be soon enough. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we need + * the info will be soon enough. */ TclInvalidateNsCmdLookup(nsPtr); @@ -1466,9 +1464,9 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) } /* - * Now link the hash table entry with the command structure. - * This is like creating a new command, so deal with any shadowing - * of commands in the global namespace. + * Now link the hash table entry with the command structure. This is like + * creating a new command, so deal with any shadowing of commands in the + * global namespace. */ cmdPtr->hPtr = hPtr; @@ -1476,18 +1474,18 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) Tcl_SetHashValue(hPtr, (ClientData) cmdPtr); /* - * Not needed as we are only in the global namespace - * (but would be needed again if we supported namespace command hiding) + * Not needed as we are only in the global namespace (but would be needed + * again if we supported namespace command hiding) * * TclResetShadowedCmdRefs(interp, cmdPtr); */ /* * If the command being exposed has a compile procedure, increment - * interpreter's compileEpoch to invalidate its compiled code. This - * makes sure that we don't later try to execute old code compiled - * assuming the command is hidden. This field is checked in Tcl_EvalObj - * and ObjInterpProc, and code whose compilation epoch doesn't match is + * interpreter's compileEpoch to invalidate its compiled code. This makes + * sure that we don't later try to execute old code compiled assuming the + * command is hidden. This field is checked in Tcl_EvalObj and + * ObjInterpProc, and code whose compilation epoch doesn't match is * recompiled. */ @@ -1505,34 +1503,34 @@ Tcl_ExposeCommand(interp, hiddenCmdToken, cmdName) * Define a new command in a command table. * * Results: - * The return value is a token for the command, which can - * be used in future calls to Tcl_GetCommandName. + * The return value is a token for the command, which can be used in + * future calls to Tcl_GetCommandName. * * Side effects: * If a command named cmdName already exists for interp, it is deleted. * In the future, when cmdName is seen as the name of a command by * Tcl_Eval, proc will be called. To support the bytecode interpreter, * the command is created with a wrapper Tcl_ObjCmdProc - * (TclInvokeStringCommand) that eventially calls proc. When the - * command is deleted from the table, deleteProc will be called. - * See the manual entry for details on the calling sequence. + * (TclInvokeStringCommand) that eventially calls proc. When the command + * is deleted from the table, deleteProc will be called. See the manual + * entry for details on the calling sequence. * *---------------------------------------------------------------------- */ Tcl_Command Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) - Tcl_Interp *interp; /* Token for command interpreter returned by - * a previous call to Tcl_CreateInterp. */ + Tcl_Interp *interp; /* Token for command interpreter returned by a + * previous call to Tcl_CreateInterp. */ CONST char *cmdName; /* Name of command. If it contains namespace * qualifiers, the new command is put in the - * specified namespace; otherwise it is put - * in the global namespace. */ + * specified namespace; otherwise it is put in + * the global namespace. */ Tcl_CmdProc *proc; /* Procedure to associate with cmdName. */ ClientData clientData; /* Arbitrary value passed to string proc. */ Tcl_CmdDeleteProc *deleteProc; - /* If not NULL, gives a procedure to call - * when this command is deleted. */ + /* If not NULL, gives a procedure to call when + * this command is deleted. */ { Interp *iPtr = (Interp *) interp; ImportRef *oldRefPtr = NULL; @@ -1545,17 +1543,17 @@ Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) if (iPtr->flags & DELETED) { /* - * The interpreter is being deleted. Don't create any new - * commands; it's not safe to muck with the interpreter anymore. + * The interpreter is being deleted. Don't create any new commands; + * it's not safe to muck with the interpreter anymore. */ return (Tcl_Command) NULL; } /* - * Determine where the command should reside. If its name contains - * namespace qualifiers, we put it in the specified namespace; - * otherwise, we always put it in the global namespace. + * Determine where the command should reside. If its name contains + * namespace qualifiers, we put it in the specified namespace; otherwise, + * we always put it in the global namespace. */ if (strstr(cmdName, "::") != NULL) { @@ -1572,10 +1570,10 @@ Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); if (!new) { /* - * Command already exists. Delete the old one. - * Be careful to preserve any existing import links so we can - * restore them down below. That way, you can redefine a - * command and its import status will remain intact. + * Command already exists. Delete the old one. Be careful to preserve + * any existing import links so we can restore them down below. That + * way, you can redefine a command and its import status will remain + * intact. */ cmdPtr = (Command *) Tcl_GetHashValue(hPtr); @@ -1586,18 +1584,18 @@ Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); if (!new) { /* - * If the deletion callback recreated the command, just throw - * away the new command (if we try to delete it again, we - * could get stuck in an infinite loop). + * If the deletion callback recreated the command, just throw away + * the new command (if we try to delete it again, we could get + * stuck in an infinite loop). */ ckfree((char*) Tcl_GetHashValue(hPtr)); } } else { /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just - * yet; next time we need the info will be soon enough. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we + * need the info will be soon enough. */ TclInvalidateNsCmdLookup(nsPtr); @@ -1621,8 +1619,8 @@ Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) cmdPtr->tracePtr = NULL; /* - * Plug in any existing import references found above. Be sure - * to update all of these references to point to the new command. + * Plug in any existing import references found above. Be sure to update + * all of these references to point to the new command. */ if (oldRefPtr != NULL) { @@ -1654,41 +1652,41 @@ Tcl_CreateCommand(interp, cmdName, proc, clientData, deleteProc) * Define a new object-based command in a command table. * * Results: - * The return value is a token for the command, which can - * be used in future calls to Tcl_GetCommandName. + * The return value is a token for the command, which can be used in + * future calls to Tcl_GetCommandName. * * Side effects: * If no command named "cmdName" already exists for interp, one is - * created. Otherwise, if a command does exist, then if the - * object-based Tcl_ObjCmdProc is TclInvokeStringCommand, we assume - * Tcl_CreateCommand was called previously for the same command and - * just set its Tcl_ObjCmdProc to the argument "proc"; otherwise, we - * delete the old command. + * created. Otherwise, if a command does exist, then if the object-based + * Tcl_ObjCmdProc is TclInvokeStringCommand, we assume Tcl_CreateCommand + * was called previously for the same command and just set its + * Tcl_ObjCmdProc to the argument "proc"; otherwise, we delete the old + * command. * * In the future, during bytecode evaluation when "cmdName" is seen as * the name of a command by Tcl_EvalObj or Tcl_Eval, the object-based * Tcl_ObjCmdProc proc will be called. When the command is deleted from - * the table, deleteProc will be called. See the manual entry for - * details on the calling sequence. + * the table, deleteProc will be called. See the manual entry for details + * on the calling sequence. * *---------------------------------------------------------------------- */ Tcl_Command Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) - Tcl_Interp *interp; /* Token for command interpreter (returned - * by previous call to Tcl_CreateInterp). */ + Tcl_Interp *interp; /* Token for command interpreter (returned by + * previous call to Tcl_CreateInterp). */ CONST char *cmdName; /* Name of command. If it contains namespace * qualifiers, the new command is put in the - * specified namespace; otherwise it is put - * in the global namespace. */ + * specified namespace; otherwise it is put in + * the global namespace. */ Tcl_ObjCmdProc *proc; /* Object-based procedure to associate with * name. */ ClientData clientData; /* Arbitrary value to pass to object * procedure. */ Tcl_CmdDeleteProc *deleteProc; - /* If not NULL, gives a procedure to call - * when this command is deleted. */ + /* If not NULL, gives a procedure to call when + * this command is deleted. */ { Interp *iPtr = (Interp *) interp; ImportRef *oldRefPtr = NULL; @@ -1701,17 +1699,17 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) if (iPtr->flags & DELETED) { /* - * The interpreter is being deleted. Don't create any new - * commands; it's not safe to muck with the interpreter anymore. + * The interpreter is being deleted. Don't create any new commands; + * it's not safe to muck with the interpreter anymore. */ return (Tcl_Command) NULL; } /* - * Determine where the command should reside. If its name contains - * namespace qualifiers, we put it in the specified namespace; - * otherwise, we always put it in the global namespace. + * Determine where the command should reside. If its name contains + * namespace qualifiers, we put it in the specified namespace; otherwise, + * we always put it in the global namespace. */ if (strstr(cmdName, "::") != NULL) { @@ -1733,7 +1731,7 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) /* * Command already exists. If its object-based Tcl_ObjCmdProc is * TclInvokeStringCommand, we just set its Tcl_ObjCmdProc to the - * argument "proc". Otherwise, we delete the old command. + * argument "proc". Otherwise, we delete the old command. */ if (cmdPtr->objProc == TclInvokeStringCommand) { @@ -1745,10 +1743,10 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) } /* - * Otherwise, we delete the old command. Be careful to preserve - * any existing import links so we can restore them down below. - * That way, you can redefine a command and its import status - * will remain intact. + * Otherwise, we delete the old command. Be careful to preserve any + * existing import links so we can restore them down below. That way, + * you can redefine a command and its import status will remain + * intact. */ oldRefPtr = cmdPtr->importRefPtr; @@ -1758,18 +1756,18 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, tail, &new); if (!new) { /* - * If the deletion callback recreated the command, just throw - * away the new command (if we try to delete it again, we - * could get stuck in an infinite loop). + * If the deletion callback recreated the command, just throw away + * the new command (if we try to delete it again, we could get + * stuck in an infinite loop). */ ckfree((char *) Tcl_GetHashValue(hPtr)); } } else { /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just - * yet; next time we need the info will be soon enough. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we + * need the info will be soon enough. */ TclInvalidateNsCmdLookup(nsPtr); @@ -1793,8 +1791,8 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) cmdPtr->tracePtr = NULL; /* - * Plug in any existing import references found above. Be sure - * to update all of these references to point to the new command. + * Plug in any existing import references found above. Be sure to update + * all of these references to point to the new command. */ if (oldRefPtr != NULL) { @@ -1825,9 +1823,9 @@ Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) * * "Wrapper" Tcl_ObjCmdProc used to call an existing string-based * Tcl_CmdProc if no object-based procedure exists for a command. A - * pointer to this procedure is stored as the Tcl_ObjCmdProc in a - * Command structure. It simply turns around and calls the string - * Tcl_CmdProc in the Command structure. + * pointer to this procedure is stored as the Tcl_ObjCmdProc in a Command + * structure. It simply turns around and calls the string Tcl_CmdProc in + * the Command structure. * * Results: * A standard Tcl object result value. @@ -1861,9 +1859,8 @@ TclInvokeStringCommand(clientData, interp, objc, objv) CONST char **argv = argStorage; /* - * Create the string argument array "argv". Make sure argv is large - * enough to hold the objc arguments plus 1 extra for the zero - * end-of-argv word. + * Create the string argument array "argv". Make sure argv is large enough + * to hold the objc arguments plus 1 extra for the zero end-of-argv word. */ if ((objc + 1) > NUM_ARGS) { @@ -1898,10 +1895,10 @@ TclInvokeStringCommand(clientData, interp, objc, objv) * TclInvokeObjectCommand -- * * "Wrapper" Tcl_CmdProc used to call an existing object-based - * Tcl_ObjCmdProc if no string-based procedure exists for a command. - * A pointer to this procedure is stored as the Tcl_CmdProc in a - * Command structure. It simply turns around and calls the object - * Tcl_ObjCmdProc in the Command structure. + * Tcl_ObjCmdProc if no string-based procedure exists for a command. A + * pointer to this procedure is stored as the Tcl_CmdProc in a Command + * structure. It simply turns around and calls the object Tcl_ObjCmdProc + * in the Command structure. * * Results: * A standard Tcl string result value. @@ -1936,9 +1933,8 @@ TclInvokeObjectCommand(clientData, interp, argc, argv) register Tcl_Obj **objv = argStorage; /* - * Create the object argument array "objv". Make sure objv is large - * enough to hold the objc arguments plus 1 extra for the zero - * end-of-objv word. + * Create the object argument array "objv". Make sure objv is large enough + * to hold the objc arguments plus 1 extra for the zero end-of-objv word. */ if (argc > NUM_ARGS) { @@ -1959,15 +1955,15 @@ TclInvokeObjectCommand(clientData, interp, argc, argv) result = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, argc, objv); /* - * Move the interpreter's object result to the string result, - * then reset the object result. + * Move the interpreter's object result to the string result, then reset + * the object result. */ (void) Tcl_GetStringResult(interp); /* - * Decrement the ref counts for the argument objects created above, - * then free the objv array if malloc'ed storage was used. + * Decrement the ref counts for the argument objects created above, then + * free the objv array if malloc'ed storage was used. */ for (i = 0; i < argc; i++) { @@ -1986,11 +1982,11 @@ TclInvokeObjectCommand(clientData, interp, argc, argv) * * TclRenameCommand -- * - * Called to give an existing Tcl command a different name. Both the - * old command name and the new command name can have "::" namespace - * qualifiers. If the new command has a different namespace context, - * the command will be moved to that namespace and will execute in - * the context of that new namespace. + * Called to give an existing Tcl command a different name. Both the old + * command name and the new command name can have "::" namespace + * qualifiers. If the new command has a different namespace context, the + * command will be moved to that namespace and will execute in the + * context of that new namespace. * * If the new command name is NULL or the null string, the command is * deleted. @@ -2022,8 +2018,8 @@ TclRenameCommand(interp, oldName, newName) Tcl_DString newFullName; /* - * Find the existing command. An error is returned if cmdName can't - * be found. + * Find the existing command. An error is returned if cmdName can't be + * found. */ cmd = Tcl_FindCommand(interp, oldName, (Tcl_Namespace *) NULL, @@ -2052,10 +2048,9 @@ TclRenameCommand(interp, oldName, newName) } /* - * Make sure that the destination command does not already exist. - * The rename operation is like creating a command, so we should - * automatically create the containing namespaces just like - * Tcl_CreateCommand would. + * Make sure that the destination command does not already exist. The + * rename operation is like creating a command, so we should automatically + * create the containing namespaces just like Tcl_CreateCommand would. */ TclGetNamespaceForQualName(interp, newName, (Namespace *) NULL, @@ -2075,15 +2070,15 @@ TclRenameCommand(interp, oldName, newName) } /* - * Warning: any changes done in the code here are likely - * to be needed in Tcl_HideCommand() code too. - * (until the common parts are extracted out) --dl + * Warning: any changes done in the code here are likely to be needed in + * Tcl_HideCommand() code too (until the common parts are extracted out). + * - dl */ /* - * Put the command in the new namespace so we can check for an alias - * loop. Since we are adding a new command to a namespace, we must - * handle any shadowing of the global commands that this might create. + * Put the command in the new namespace so we can check for an alias loop. + * Since we are adding a new command to a namespace, we must handle any + * shadowing of the global commands that this might create. */ oldHPtr = cmdPtr->hPtr; @@ -2094,8 +2089,8 @@ TclRenameCommand(interp, oldName, newName) TclResetShadowedCmdRefs(interp, cmdPtr); /* - * Now check for an alias loop. If we detect one, put everything back - * the way it was and report the error. + * Now check for an alias loop. If we detect one, put everything back the + * way it was and report the error. */ result = TclPreventAliasLoop(interp, interp, (Tcl_Command) cmdPtr); @@ -2107,25 +2102,25 @@ TclRenameCommand(interp, oldName, newName) } /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just yet; - * next time we need the info will be soon enough. These might - * refer to the same variable, but that's no big deal. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we need + * the info will be soon enough. These might refer to the same variable, + * but that's no big deal. */ TclInvalidateNsCmdLookup(cmdNsPtr); TclInvalidateNsCmdLookup(cmdPtr->nsPtr); /* - * Script for rename traces can delete the command "oldName". - * Therefore increment the reference count for cmdPtr so that - * it's Command structure is freed only towards the end of this - * function by calling TclCleanupCommand. + * Script for rename traces can delete the command "oldName". Therefore + * increment the reference count for cmdPtr so that it's Command structure + * is freed only towards the end of this function by calling + * TclCleanupCommand. * - * The trace procedure needs to get a fully qualified name for - * old and new commands [Tcl bug #651271], or else there's no way - * for the trace procedure to get the namespace from which the old - * command is being renamed! + * The trace procedure needs to get a fully qualified name for old and new + * commands [Tcl bug #651271], or else there's no way for the trace + * procedure to get the namespace from which the old command is being + * renamed! */ Tcl_DStringInit(&newFullName); @@ -2140,9 +2135,9 @@ TclRenameCommand(interp, oldName, newName) Tcl_DStringFree(&newFullName); /* - * The new command name is okay, so remove the command from its - * current namespace. This is like deleting the command, so bump - * the cmdEpoch to invalidate any cached references to the command. + * The new command name is okay, so remove the command from its current + * namespace. This is like deleting the command, so bump the cmdEpoch to + * invalidate any cached references to the command. */ Tcl_DeleteHashEntry(oldHPtr); @@ -2150,9 +2145,9 @@ TclRenameCommand(interp, oldName, newName) /* * If the command being renamed has a compile procedure, increment the - * interpreter's compileEpoch to invalidate its compiled code. This - * makes sure that we don't later try to execute old code compiled for - * the now-renamed command. + * interpreter's compileEpoch to invalidate its compiled code. This makes + * sure that we don't later try to execute old code compiled for the + * now-renamed command. */ if (cmdPtr->compileProc != NULL) { @@ -2160,13 +2155,14 @@ TclRenameCommand(interp, oldName, newName) } /* - * Now free the Command structure, if the "oldName" command has - * been deleted by invocation of rename traces. + * Now free the Command structure, if the "oldName" command has been + * deleted by invocation of rename traces. */ + TclCleanupCommand(cmdPtr); result = TCL_OK; - done: + done: TclDecrRefCount(oldFullName); return result; } @@ -2176,16 +2172,15 @@ TclRenameCommand(interp, oldName, newName) * * Tcl_SetCommandInfo -- * - * Modifies various information about a Tcl command. Note that - * this procedure will not change a command's namespace; use - * TclRenameCommand to do that. Also, the isNativeObjectProc - * member of *infoPtr is ignored. + * Modifies various information about a Tcl command. Note that this + * procedure will not change a command's namespace; use TclRenameCommand + * to do that. Also, the isNativeObjectProc member of *infoPtr is + * ignored. * * Results: - * If cmdName exists in interp, then the information at *infoPtr - * is stored with the command in place of the current information - * and 1 is returned. If the command doesn't exist then 0 is - * returned. + * If cmdName exists in interp, then the information at *infoPtr is + * stored with the command in place of the current information and 1 is + * returned. If the command doesn't exist then 0 is returned. * * Side effects: * None. @@ -2195,11 +2190,11 @@ TclRenameCommand(interp, oldName, newName) int Tcl_SetCommandInfo(interp, cmdName, infoPtr) - Tcl_Interp *interp; /* Interpreter in which to look - * for command. */ - CONST char *cmdName; /* Name of desired command. */ - CONST Tcl_CmdInfo *infoPtr; /* Where to find information - * to store in the command. */ + Tcl_Interp *interp; /* Interpreter in which to look for + * command. */ + CONST char *cmdName; /* Name of desired command. */ + CONST Tcl_CmdInfo *infoPtr; /* Where to find information to store in the + * command. */ { Tcl_Command cmd; @@ -2215,16 +2210,15 @@ Tcl_SetCommandInfo(interp, cmdName, infoPtr) * * Tcl_SetCommandInfoFromToken -- * - * Modifies various information about a Tcl command. Note that - * this procedure will not change a command's namespace; use - * TclRenameCommand to do that. Also, the isNativeObjectProc - * member of *infoPtr is ignored. + * Modifies various information about a Tcl command. Note that this + * procedure will not change a command's namespace; use TclRenameCommand + * to do that. Also, the isNativeObjectProc member of *infoPtr is + * ignored. * * Results: - * If cmdName exists in interp, then the information at *infoPtr - * is stored with the command in place of the current information - * and 1 is returned. If the command doesn't exist then 0 is - * returned. + * If cmdName exists in interp, then the information at *infoPtr is + * stored with the command in place of the current information and 1 is + * returned. If the command doesn't exist then 0 is returned. * * Side effects: * None. @@ -2270,10 +2264,9 @@ Tcl_SetCommandInfoFromToken(cmd, infoPtr) * Returns various information about a Tcl command. * * Results: - * If cmdName exists in interp, then *infoPtr is modified to - * hold information about cmdName and 1 is returned. If the - * command doesn't exist then 0 is returned and *infoPtr isn't - * modified. + * If cmdName exists in interp, then *infoPtr is modified to hold + * information about cmdName and 1 is returned. If the command doesn't + * exist then 0 is returned and *infoPtr isn't modified. * * Side effects: * None. @@ -2283,11 +2276,11 @@ Tcl_SetCommandInfoFromToken(cmd, infoPtr) int Tcl_GetCommandInfo(interp, cmdName, infoPtr) - Tcl_Interp *interp; /* Interpreter in which to look - * for command. */ - CONST char *cmdName; /* Name of desired command. */ - Tcl_CmdInfo *infoPtr; /* Where to store information about - * command. */ + Tcl_Interp *interp; /* Interpreter in which to look for + * command. */ + CONST char *cmdName; /* Name of desired command. */ + Tcl_CmdInfo *infoPtr; /* Where to store information about + * command. */ { Tcl_Command cmd; @@ -2306,9 +2299,9 @@ Tcl_GetCommandInfo(interp, cmdName, infoPtr) * Returns various information about a Tcl command. * * Results: - * Copies information from the command identified by 'cmd' into - * a caller-supplied structure and returns 1. If the 'cmd' is - * NULL, leaves the structure untouched and returns 0. + * Copies information from the command identified by 'cmd' into a + * caller-supplied structure and returns 1. If the 'cmd' is NULL, leaves + * the structure untouched and returns 0. * * Side effects: * None. @@ -2321,7 +2314,6 @@ Tcl_GetCommandInfoFromToken(cmd, infoPtr) Tcl_Command cmd; Tcl_CmdInfo* infoPtr; { - Command* cmdPtr; /* Internal representation of the command */ if (cmd == (Tcl_Command) NULL) { @@ -2353,9 +2345,9 @@ Tcl_GetCommandInfoFromToken(cmd, infoPtr) * * Tcl_GetCommandName -- * - * Given a token returned by Tcl_CreateCommand, this procedure - * returns the current name of the command (which may have changed - * due to renaming). + * Given a token returned by Tcl_CreateCommand, this procedure returns + * the current name of the command (which may have changed due to + * renaming). * * Results: * The return value is the name of the given command. @@ -2370,21 +2362,21 @@ CONST char * Tcl_GetCommandName(interp, command) Tcl_Interp *interp; /* Interpreter containing the command. */ Tcl_Command command; /* Token for command returned by a previous - * call to Tcl_CreateCommand. The command - * must not have been deleted. */ + * call to Tcl_CreateCommand. The command must + * not have been deleted. */ { Command *cmdPtr = (Command *) command; if ((cmdPtr == NULL) || (cmdPtr->hPtr == NULL)) { - /* * This should only happen if command was "created" after the - * interpreter began to be deleted, so there isn't really any - * command. Just return an empty string. + * interpreter began to be deleted, so there isn't really any command. + * Just return an empty string. */ return ""; } + return Tcl_GetHashKey(cmdPtr->hPtr->tablePtr, cmdPtr->hPtr); } @@ -2393,17 +2385,17 @@ Tcl_GetCommandName(interp, command) * * Tcl_GetCommandFullName -- * - * Given a token returned by, e.g., Tcl_CreateCommand or - * Tcl_FindCommand, this procedure appends to an object the command's - * full name, qualified by a sequence of parent namespace names. The - * command's fully-qualified name may have changed due to renaming. + * Given a token returned by, e.g., Tcl_CreateCommand or Tcl_FindCommand, + * this procedure appends to an object the command's full name, qualified + * by a sequence of parent namespace names. The command's fully-qualified + * name may have changed due to renaming. * * Results: * None. * * Side effects: * The command's fully-qualified name is appended to the string - * representation of objPtr. + * representation of objPtr. * *---------------------------------------------------------------------- */ @@ -2412,8 +2404,8 @@ void Tcl_GetCommandFullName(interp, command, objPtr) Tcl_Interp *interp; /* Interpreter containing the command. */ Tcl_Command command; /* Token for command returned by a previous - * call to Tcl_CreateCommand. The command - * must not have been deleted. */ + * call to Tcl_CreateCommand. The command must + * not have been deleted. */ Tcl_Obj *objPtr; /* Points to the object onto which the * command's full name is appended. */ @@ -2449,20 +2441,19 @@ Tcl_GetCommandFullName(interp, command, objPtr) * Remove the given command from the given interpreter. * * Results: - * 0 is returned if the command was deleted successfully. - * -1 is returned if there didn't exist a command by that name. + * 0 is returned if the command was deleted successfully. -1 is returned + * if there didn't exist a command by that name. * * Side effects: - * cmdName will no longer be recognized as a valid command for - * interp. + * cmdName will no longer be recognized as a valid command for interp. * *---------------------------------------------------------------------- */ int Tcl_DeleteCommand(interp, cmdName) - Tcl_Interp *interp; /* Token for command interpreter (returned - * by a previous Tcl_CreateInterp call). */ + Tcl_Interp *interp; /* Token for command interpreter (returned by + * a previous Tcl_CreateInterp call). */ CONST char *cmdName; /* Name of command to remove. */ { Tcl_Command cmd; @@ -2485,24 +2476,24 @@ Tcl_DeleteCommand(interp, cmdName) * Tcl_DeleteCommandFromToken -- * * Removes the given command from the given interpreter. This procedure - * resembles Tcl_DeleteCommand, but takes a Tcl_Command token instead - * of a command name for efficiency. + * resembles Tcl_DeleteCommand, but takes a Tcl_Command token instead of + * a command name for efficiency. * * Results: - * 0 is returned if the command was deleted successfully. - * -1 is returned if there didn't exist a command by that name. + * 0 is returned if the command was deleted successfully. -1 is returned + * if there didn't exist a command by that name. * * Side effects: - * The command specified by "cmd" will no longer be recognized as a - * valid command for "interp". + * The command specified by "cmd" will no longer be recognized as a valid + * command for "interp". * *---------------------------------------------------------------------- */ int Tcl_DeleteCommandFromToken(interp, cmd) - Tcl_Interp *interp; /* Token for command interpreter returned by - * a previous call to Tcl_CreateInterp. */ + Tcl_Interp *interp; /* Token for command interpreter returned by a + * previous call to Tcl_CreateInterp. */ Tcl_Command cmd; /* Token for command to delete. */ { Interp *iPtr = (Interp *) interp; @@ -2511,22 +2502,21 @@ Tcl_DeleteCommandFromToken(interp, cmd) Tcl_Command importCmd; /* - * The code here is tricky. We can't delete the hash table entry - * before invoking the deletion callback because there are cases - * where the deletion callback needs to invoke the command (e.g. - * object systems such as OTcl). However, this means that the - * callback could try to delete or rename the command. The deleted - * flag allows us to detect these cases and skip nested deletes. + * The code here is tricky. We can't delete the hash table entry before + * invoking the deletion callback because there are cases where the + * deletion callback needs to invoke the command (e.g. object systems such + * as OTcl). However, this means that the callback could try to delete or + * rename the command. The deleted flag allows us to detect these cases + * and skip nested deletes. */ if (cmdPtr->flags & CMD_IS_DELETED) { /* - * Another deletion is already in progress. Remove the hash - * table entry now, but don't invoke a callback or free the - * command structure. Take care to only remove the hash entry - * if it has not already been removed; otherwise if we manage - * to hit this function three times, everything goes up in - * smoke. [Bug 1220058] + * Another deletion is already in progress. Remove the hash table + * entry now, but don't invoke a callback or free the command + * structure. Take care to only remove the hash entry if it has not + * already been removed; otherwise if we manage to hit this function + * three times, everything goes up in smoke. [Bug 1220058] */ if (cmdPtr->hPtr != NULL) { @@ -2536,24 +2526,29 @@ Tcl_DeleteCommandFromToken(interp, cmd) return 0; } - /* - * We must delete this command, even though both traces and - * delete procs may try to avoid this (renaming the command etc). - * Also traces and delete procs may try to delete the command - * themsevles. This flag declares that a delete is in progress - * and that recursive deletes should be ignored. + /* + * We must delete this command, even though both traces and delete procs + * may try to avoid this (renaming the command etc). Also traces and + * delete procs may try to delete the command themsevles. This flag + * declares that a delete is in progress and that recursive deletes should + * be ignored. */ + cmdPtr->flags |= CMD_IS_DELETED; /* - * Call trace procedures for the command being deleted. Then delete - * its traces. + * Call trace procedures for the command being deleted. Then delete its + * traces. */ if (cmdPtr->tracePtr != NULL) { CommandTrace *tracePtr; CallCommandTraces(iPtr,cmdPtr,NULL,NULL,TCL_TRACE_DELETE); - /* Now delete these traces */ + + /* + * Now delete these traces. + */ + tracePtr = cmdPtr->tracePtr; while (tracePtr != NULL) { CommandTrace *nextPtr = tracePtr->nextPtr; @@ -2566,20 +2561,20 @@ Tcl_DeleteCommandFromToken(interp, cmd) } /* - * The list of command exported from the namespace might have - * changed. However, we do not need to recompute this just yet; - * next time we need the info will be soon enough. + * The list of command exported from the namespace might have changed. + * However, we do not need to recompute this just yet; next time we need + * the info will be soon enough. */ TclInvalidateNsCmdLookup(cmdPtr->nsPtr); /* * If the command being deleted has a compile procedure, increment the - * interpreter's compileEpoch to invalidate its compiled code. This - * makes sure that we don't later try to execute old code compiled with - * command-specific (i.e., inline) bytecodes for the now-deleted - * command. This field is checked in Tcl_EvalObj and ObjInterpProc, and - * code whose compilation epoch doesn't match is recompiled. + * interpreter's compileEpoch to invalidate its compiled code. This makes + * sure that we don't later try to execute old code compiled with + * command-specific (i.e., inline) bytecodes for the now-deleted command. + * This field is checked in Tcl_EvalObj and ObjInterpProc, and code whose + * compilation epoch doesn't match is recompiled. */ if (cmdPtr->compileProc != NULL) { @@ -2596,12 +2591,12 @@ Tcl_DeleteCommandFromToken(interp, cmd) /* * If you are getting a crash during the call to deleteProc and - * cmdPtr->deleteProc is a pointer to the function free(), the - * most likely cause is that your extension allocated memory - * for the clientData argument to Tcl_CreateObjCommand() with - * the ckalloc() macro and you are now trying to deallocate - * this memory with free() instead of ckfree(). You should - * pass a pointer to your own method that calls ckfree(). + * cmdPtr->deleteProc is a pointer to the function free(), the most + * likely cause is that your extension allocated memory for the + * clientData argument to Tcl_CreateObjCommand() with the ckalloc() + * macro and you are now trying to deallocate this memory with free() + * instead of ckfree(). You should pass a pointer to your own method + * that calls ckfree(). */ (*cmdPtr->deleteProc)(cmdPtr->deleteData); @@ -2628,10 +2623,10 @@ Tcl_DeleteCommandFromToken(interp, cmd) } /* - * Don't use hPtr to delete the hash entry here, because it's - * possible that the deletion callback renamed the command. - * Instead, use cmdPtr->hptr, and make sure that no-one else - * has already deleted the hash entry. + * Don't use hPtr to delete the hash entry here, because it's possible + * that the deletion callback renamed the command. Instead, use + * cmdPtr->hptr, and make sure that no-one else has already deleted the + * hash entry. */ if (cmdPtr->hPtr != NULL) { @@ -2642,19 +2637,19 @@ Tcl_DeleteCommandFromToken(interp, cmd) * Mark the Command structure as no longer valid. This allows * TclExecuteByteCode to recognize when a Command has logically been * deleted and a pointer to this Command structure cached in a CmdName - * object is invalid. TclExecuteByteCode will look up the command again - * in the interpreter's command hashtable. + * object is invalid. TclExecuteByteCode will look up the command again in + * the interpreter's command hashtable. */ cmdPtr->objProc = NULL; /* - * Now free the Command structure, unless there is another reference to - * it from a CmdName Tcl object in some ByteCode code sequence. In that - * case, delay the cleanup until all references are either discarded - * (when a ByteCode is freed) or replaced by a new reference (when a - * cached CmdName Command reference is found to be invalid and - * TclExecuteByteCode looks up the command in the command hashtable). + * Now free the Command structure, unless there is another reference to it + * from a CmdName Tcl object in some ByteCode code sequence. In that case, + * delay the cleanup until all references are either discarded (when a + * ByteCode is freed) or replaced by a new reference (when a cached + * CmdName Command reference is found to be invalid and TclExecuteByteCode + * looks up the command in the command hashtable). */ TclCleanupCommand(cmdPtr); @@ -2664,15 +2659,14 @@ Tcl_DeleteCommandFromToken(interp, cmd) static char * CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) Interp *iPtr; /* Interpreter containing command. */ - Command *cmdPtr; /* Command whose traces are to be - * invoked. */ - CONST char *oldName; /* Command's old name, or NULL if we - * must get the name from cmdPtr */ - CONST char *newName; /* Command's new name, or NULL if - * the command is not being renamed */ - int flags; /* Flags indicating the type of traces - * to trigger, either TCL_TRACE_DELETE - * or TCL_TRACE_RENAME. */ + Command *cmdPtr; /* Command whose traces are to be invoked. */ + CONST char *oldName; /* Command's old name, or NULL if we must get + * the name from cmdPtr */ + CONST char *newName; /* Command's new name, or NULL if the command + * is not being renamed */ + int flags; /* Flags indicating the type of traces to + * trigger, either TCL_TRACE_DELETE or + * TCL_TRACE_RENAME. */ { register CommandTrace *tracePtr; ActiveCommandTrace active; @@ -2680,16 +2674,17 @@ CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) Tcl_Obj *oldNamePtr = NULL; if (cmdPtr->flags & CMD_TRACE_ACTIVE) { - /* - * While a rename trace is active, we will not process any more - * rename traces; while a delete trace is active we will never - * reach here -- because Tcl_DeleteCommandFromToken checks for the - * condition (cmdPtr->flags & CMD_IS_DELETED) and returns immediately - * when a command deletion is in progress. For all other traces, - * delete traces will not be invoked but a call to TraceCommandProc - * will ensure that tracePtr->clientData is freed whenever the - * command "oldName" is deleted. + /* + * While a rename trace is active, we will not process any more rename + * traces; while a delete trace is active we will never reach here - + * because Tcl_DeleteCommandFromToken checks for the condition + * (cmdPtr->flags & CMD_IS_DELETED) and returns immediately when a + * command deletion is in progress. For all other traces, delete + * traces will not be invoked but a call to TraceCommandProc will + * ensure that tracePtr->clientData is freed whenever the command + * "oldName" is deleted. */ + if (cmdPtr->flags & TCL_TRACE_RENAME) { flags &= ~TCL_TRACE_RENAME; } @@ -2722,7 +2717,7 @@ CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) if (oldName == NULL) { TclNewObj(oldNamePtr); Tcl_IncrRefCount(oldNamePtr); - Tcl_GetCommandFullName((Tcl_Interp *) iPtr, + Tcl_GetCommandFullName((Tcl_Interp *) iPtr, (Tcl_Command) cmdPtr, oldNamePtr); oldName = TclGetString(oldNamePtr); } @@ -2736,8 +2731,7 @@ CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) } /* - * If a new object was created to hold the full oldName, - * free it now. + * If a new object was created to hold the full oldName, free it now. */ if (oldNamePtr != NULL) { @@ -2745,8 +2739,8 @@ CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) } /* - * Restore the variable's flags, remove the record of our active - * traces, and then return. + * Restore the variable's flags, remove the record of our active traces, + * and then return. */ cmdPtr->flags &= ~CMD_TRACE_ACTIVE; @@ -2764,7 +2758,7 @@ CallCommandTraces(iPtr, cmdPtr, oldName, newName, flags) * This procedure frees up a Command structure unless it is still * referenced from an interpreter's command hashtable or from a CmdName * Tcl object representing the name of a command in a ByteCode - * instruction sequence. + * instruction sequence. * * Results: * None. @@ -2793,18 +2787,17 @@ TclCleanupCommand(cmdPtr) * * Tcl_CreateMathFunc -- * - * Creates a new math function for expressions in a given - * interpreter. + * Creates a new math function for expressions in a given interpreter. * * Results: * None. * * Side effects: * The function defined by "name" is created or redefined. If the - * function already exists then its definition is replaced; this - * includes the builtin functions. Redefining a builtin function forces - * all existing code to be invalidated since that code may be compiled - * using an instruction specific to the replaced function. In addition, + * function already exists then its definition is replaced; this includes + * the builtin functions. Redefining a builtin function forces all + * existing code to be invalidated since that code may be compiled using + * an instruction specific to the replaced function. In addition, * redefioning a non-builtin function will force existing code to be * invalidated if the number of arguments has changed. * @@ -2813,23 +2806,23 @@ TclCleanupCommand(cmdPtr) void Tcl_CreateMathFunc(interp, name, numArgs, argTypes, proc, clientData) - Tcl_Interp *interp; /* Interpreter in which function is - * to be available. */ - CONST char *name; /* Name of function (e.g. "sin"). */ - int numArgs; /* Nnumber of arguments required by - * function. */ - Tcl_ValueType *argTypes; /* Array of types acceptable for - * each argument. */ - Tcl_MathProc *proc; /* Procedure that implements the - * math function. */ - ClientData clientData; /* Additional value to pass to the - * function. */ + Tcl_Interp *interp; /* Interpreter in which function is to be + * available. */ + CONST char *name; /* Name of function (e.g. "sin"). */ + int numArgs; /* Nnumber of arguments required by + * function. */ + Tcl_ValueType *argTypes; /* Array of types acceptable for each + * argument. */ + Tcl_MathProc *proc; /* Procedure that implements the math + * function. */ + ClientData clientData; /* Additional value to pass to the + * function. */ { Tcl_DString bigName; - OldMathFuncData* data = (OldMathFuncData*) - Tcl_Alloc(sizeof(OldMathFuncData)); + OldMathFuncData *data = (OldMathFuncData *) + ckalloc(sizeof(OldMathFuncData)); if (numArgs > MAX_MATH_ARGS) { Tcl_Panic("attempt to create a math function with too many args"); @@ -2869,11 +2862,11 @@ Tcl_CreateMathFunc(interp, name, numArgs, argTypes, proc, clientData) static int OldMathFuncProc(clientData, interp, objc, objv) - ClientData clientData; /* Ponter to OldMathFuncData describing - * the function being called */ - Tcl_Interp* interp; /* Tcl interpreter */ - int objc; /* Actual parameter count */ - Tcl_Obj *CONST *objv; /* Parameter vector */ + ClientData clientData; /* Ponter to OldMathFuncData describing the + * function being called */ + Tcl_Interp *interp; /* Tcl interpreter */ + int objc; /* Actual parameter count */ + Tcl_Obj *CONST *objv; /* Parameter vector */ { Tcl_Obj* valuePtr; OldMathFuncData* dataPtr = (OldMathFuncData*) clientData; @@ -2886,14 +2879,18 @@ OldMathFuncProc(clientData, interp, objc, objv) int j, k; double d; - /* Check argument count */ + /* + * Check argument count. + */ if (objc != dataPtr->numArgs + 1) { MathFuncWrongNumArgs(interp, dataPtr->numArgs+1, objc, objv); return TCL_ERROR; } - /* Convert arguments from Tcl_Obj's to Tcl_Value's */ + /* + * Convert arguments from Tcl_Obj's to Tcl_Value's. + */ #if 0 for (j = 1, k = 0; j < objc; ++j, ++k) { @@ -2903,8 +2900,8 @@ OldMathFuncProc(clientData, interp, objc, objv) } /* - * Copy the object's numeric value to the argument record, - * converting it if necessary. + * Copy the object's numeric value to the argument record, converting + * it if necessary. */ if (valuePtr->typePtr == &tclIntType) { @@ -3010,16 +3007,19 @@ OldMathFuncProc(clientData, interp, objc, objv) } #endif - /* Call the function */ + /* + * Call the function. + */ errno = 0; - result = (*dataPtr->proc)(dataPtr->clientData, interp, args, - &funcResult); + result = (*dataPtr->proc)(dataPtr->clientData, interp, args, &funcResult); if (result != TCL_OK) { return result; } - /* Return the result of the call */ + /* + * Return the result of the call. + */ if (funcResult.type == TCL_INT) { TclNewLongObj(valuePtr, funcResult.intValue); @@ -3067,24 +3067,24 @@ OldMathFuncDeleteProc(clientData) * interpreter. * * Results: - * TCL_OK if it succeeds, TCL_ERROR else (leaving an error message - * in the interpreter result if that happens.) + * TCL_OK if it succeeds, TCL_ERROR else (leaving an error message in the + * interpreter result if that happens.) * * Side effects: - * If this function succeeds, the variables pointed to by the - * numArgsPtr and argTypePtr arguments will be updated to detail the - * arguments allowed by the function. The variable pointed to by the - * procPtr argument will be set to NULL if the function is a builtin - * function, and will be set to the address of the C function used to - * implement the math function otherwise (in which case the variable - * pointed to by the clientDataPtr argument will also be updated.) + * If this function succeeds, the variables pointed to by the numArgsPtr + * and argTypePtr arguments will be updated to detail the arguments + * allowed by the function. The variable pointed to by the procPtr + * argument will be set to NULL if the function is a builtin function, + * and will be set to the address of the C function used to implement the + * math function otherwise (in which case the variable pointed to by the + * clientDataPtr argument will also be updated.) * *---------------------------------------------------------------------- */ int Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, - clientDataPtr) + clientDataPtr) Tcl_Interp *interp; CONST char *name; int *numArgsPtr; @@ -3092,11 +3092,12 @@ Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, Tcl_MathProc **procPtr; ClientData *clientDataPtr; { - Tcl_Obj* cmdNameObj; Command* cmdPtr; - /* Get the command that implements the math function */ + /* + * Get the command that implements the math function. + */ cmdNameObj = Tcl_NewStringObj("tcl::mathfunc::", -1); Tcl_AppendToObj(cmdNameObj, name, -1); @@ -3104,22 +3105,24 @@ Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, cmdPtr = (Command*) Tcl_GetCommandFromObj(interp, cmdNameObj); Tcl_DecrRefCount(cmdNameObj); - /* Report unknown functions */ + /* + * Report unknown functions. + */ if (cmdPtr == NULL) { Tcl_Obj* message; message = Tcl_NewStringObj("unknown math function \"", -1); Tcl_AppendToObj(message, name, -1); Tcl_AppendToObj(message, "\"", 1); - *numArgsPtr = -1; *argTypesPtr = NULL; + *numArgsPtr = -1; *argTypesPtr = NULL; *procPtr = NULL; *clientDataPtr = NULL; return TCL_ERROR; } - /* - * Retrieve function info for user defined functions; return - * dummy information for builtins. + /* + * Retrieve function info for user defined functions; return dummy + * information for builtins. */ if (cmdPtr->objProc == &OldMathFuncProc) { @@ -3148,9 +3151,9 @@ Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, * interpreter. * * Results: - * A pointer to a Tcl_Obj structure with a reference count of zero, - * or NULL in the case of an error (in which case a suitable error - * message will be left in the interpreter result.) + * A pointer to a Tcl_Obj structure with a reference count of zero, or + * NULL in the case of an error (in which case a suitable error message + * will be left in the interpreter result.) * * Side effects: * None. @@ -3203,13 +3206,12 @@ Tcl_ListMathFuncs(interp, pattern) * * TclInterpReady -- * - * Check if an interpreter is ready to eval commands or scripts, - * i.e., if it was not deleted and if the nesting level is not - * too high. + * Check if an interpreter is ready to eval commands or scripts, i.e., if + * it was not deleted and if the nesting level is not too high. * * Results: - * The return value is TCL_OK if it the interpreter is ready, - * TCL_ERROR otherwise. + * The return value is TCL_OK if it the interpreter is ready, TCL_ERROR + * otherwise. * * Side effects: * The interpreters object and string results are cleared. @@ -3217,15 +3219,15 @@ Tcl_ListMathFuncs(interp, pattern) *---------------------------------------------------------------------- */ -int +int TclInterpReady(interp) Tcl_Interp *interp; { register Interp *iPtr = (Interp *) interp; /* - * Reset both the interpreter's string and object results and clear - * out any previous error information. + * Reset both the interpreter's string and object results and clear out + * any previous error information. */ Tcl_ResetResult(interp); @@ -3244,14 +3246,14 @@ TclInterpReady(interp) } /* - * Check depth of nested calls to Tcl_Eval: if this gets too large, - * it's probably because of an infinite loop somewhere. + * Check depth of nested calls to Tcl_Eval: if this gets too large, it's + * probably because of an infinite loop somewhere. */ - if (((iPtr->numLevels) > iPtr->maxNestingDepth) + if (((iPtr->numLevels) > iPtr->maxNestingDepth) || (TclpCheckStackSpace() == 0)) { Tcl_AppendResult(interp, - "too many nested evaluations (infinite loop?)", (char *) NULL); + "too many nested evaluations (infinite loop?)", (char *) NULL); return TCL_ERROR; } @@ -3263,15 +3265,15 @@ TclInterpReady(interp) * * TclEvalObjvInternal -- * - * This procedure evaluates a Tcl command that has already been - * parsed into words, with one Tcl_Obj holding each word. The caller - * is responsible for managing the iPtr->numLevels. + * This procedure evaluates a Tcl command that has already been parsed + * into words, with one Tcl_Obj holding each word. The caller is + * responsible for managing the iPtr->numLevels. * * Results: - * The return value is a standard Tcl completion code such as - * TCL_OK or TCL_ERROR. A result or error message is left in - * interp's result. If an error occurs, this procedure does - * NOT add any information to the errorInfo variable. + * The return value is a standard Tcl completion code such as TCL_OK or + * TCL_ERROR. A result or error message is left in interp's result. If an + * error occurs, this procedure does NOT add any information to the + * errorInfo variable. * * Side effects: * Depends on the command. @@ -3282,23 +3284,21 @@ TclInterpReady(interp) int TclEvalObjvInternal(interp, objc, objv, command, length, flags) Tcl_Interp *interp; /* Interpreter in which to evaluate the - * command. Also used for error - * reporting. */ + * command. Also used for error reporting. */ int objc; /* Number of words in command. */ Tcl_Obj *CONST objv[]; /* An array of pointers to objects that are * the words that make up the command. */ CONST char *command; /* Points to the beginning of the string - * representation of the command; this - * is used for traces. If the string - * representation of the command is - * unknown, an empty string should be - * supplied. If it is NULL, no traces will - * be called. */ + * representation of the command; this is used + * for traces. If the string representation of + * the command is unknown, an empty string + * should be supplied. If it is NULL, no + * traces will be called. */ int length; /* Number of bytes in command; if -1, all * characters up to the first null byte are * used. */ - int flags; /* Collection of OR-ed bits that control - * the evaluation of the script. Only + int flags; /* Collection of OR-ed bits that control the + * evaluation of the script. Only * TCL_EVAL_GLOBAL and TCL_EVAL_INVOKE are * currently supported. */ @@ -3307,8 +3307,8 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) Interp *iPtr = (Interp *) interp; Tcl_Obj **newObjv; int i; - CallFrame *savedVarFramePtr; /* Saves old copy of iPtr->varFramePtr - * in case TCL_EVAL_GLOBAL was set. */ + CallFrame *savedVarFramePtr;/* Saves old copy of iPtr->varFramePtr in case + * TCL_EVAL_GLOBAL was set. */ int code = TCL_OK; int traceCode = TCL_OK; int checkTraces = 1; @@ -3322,18 +3322,17 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) } /* - * Find the procedure to execute this command. If there isn't one, - * then see if there is a command "unknown". If so, create a new - * word array with "unknown" as the first word and the original - * command words as arguments. Then call ourselves recursively to - * execute it. + * Find the procedure to execute this command. If there isn't one, then + * see if there is a command "unknown". If so, create a new word array + * with "unknown" as the first word and the original command words as + * arguments. Then call ourselves recursively to execute it. * * If caller requests, or if we're resolving the target end of an * interpeter alias (TCL_EVAL_INVOKE), be sure to do command name * resolution in the global namespace. * - * If any execution traces rename or delete the current command, - * we may need (at most) two passes here. + * If any execution traces rename or delete the current command, we may + * need (at most) two passes here. */ reparseBecauseOfTraces: @@ -3345,8 +3344,8 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) iPtr->varFramePtr = savedVarFramePtr; if (cmdPtr == NULL) { - newObjv = (Tcl_Obj **) ckalloc((unsigned) - ((objc + 1) * sizeof(Tcl_Obj *))); + newObjv = (Tcl_Obj **) + ckalloc((unsigned) ((objc + 1) * sizeof(Tcl_Obj *))); for (i = objc-1; i >= 0; i--) { newObjv[i+1] = objv[i]; } @@ -3371,14 +3370,17 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) /* * Call trace procedures if needed. */ + if ((checkTraces) && (command != NULL)) { int cmdEpoch = cmdPtr->cmdEpoch; cmdPtr->refCount++; - /* - * If the first set of traces modifies/deletes the command or - * any existing traces, then the set checkTraces to 0 and go - * through this while loop one more time. + + /* + * If the first set of traces modifies/deletes the command or any + * existing traces, then the set checkTraces to 0 and go through this + * while loop one more time. */ + if (iPtr->tracePtr != NULL && traceCode == TCL_OK) { traceCode = TclCheckInterpTraces(interp, command, length, cmdPtr, code, TCL_TRACE_ENTER_EXEC, objc, objv); @@ -3389,7 +3391,10 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) } cmdPtr->refCount--; if (cmdEpoch != cmdPtr->cmdEpoch) { - /* The command has been modified in some way */ + /* + * The command has been modified in some way. + */ + checkTraces = 0; goto reparseBecauseOfTraces; } @@ -3398,6 +3403,7 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) /* * Finally, invoke the command's Tcl_ObjCmdProc. */ + cmdPtr->refCount++; iPtr->cmdCount++; if (code == TCL_OK && traceCode == TCL_OK && !Tcl_LimitExceeded(interp)) { @@ -3423,6 +3429,7 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) /* * Call 'leave' command traces */ + if (!(cmdPtr->flags & CMD_IS_DELETED)) { if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) && (traceCode == TCL_OK)) { traceCode = TclCheckExecutionTraces(interp, command, length, @@ -3436,10 +3443,9 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) TclCleanupCommand(cmdPtr); /* - * If one of the trace invocation resulted in error, then - * change the result code accordingly. Note, that the - * interp->result should already be set correctly by the - * call to TraceExecutionProc. + * If one of the trace invocation resulted in error, then change the + * result code accordingly. Note, that the interp->result should already + * be set correctly by the call to TraceExecutionProc. */ if (traceCode != TCL_OK) { @@ -3447,17 +3453,17 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) } /* - * If the interpreter has a non-empty string result, the result - * object is either empty or stale because some procedure set - * interp->result directly. If so, move the string result to the - * result object, then reset the string result. + * If the interpreter has a non-empty string result, the result object is + * either empty or stale because some procedure set interp->result + * directly. If so, move the string result to the result object, then + * reset the string result. */ if (*(iPtr->result) != 0) { (void) Tcl_GetObjResult(interp); } - done: + done: return code; } @@ -3466,13 +3472,12 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) * * Tcl_EvalObjv -- * - * This procedure evaluates a Tcl command that has already been - * parsed into words, with one Tcl_Obj holding each word. + * This procedure evaluates a Tcl command that has already been parsed + * into words, with one Tcl_Obj holding each word. * * Results: - * The return value is a standard Tcl completion code such as - * TCL_OK or TCL_ERROR. A result or error message is left in - * interp's result. + * The return value is a standard Tcl completion code such as TCL_OK or + * TCL_ERROR. A result or error message is left in interp's result. * * Side effects: * Depends on the command. @@ -3483,15 +3488,14 @@ TclEvalObjvInternal(interp, objc, objv, command, length, flags) int Tcl_EvalObjv(interp, objc, objv, flags) Tcl_Interp *interp; /* Interpreter in which to evaluate the - * command. Also used for error - * reporting. */ + * command. Also used for error reporting. */ int objc; /* Number of words in command. */ Tcl_Obj *CONST objv[]; /* An array of pointers to objects that are * the words that make up the command. */ - int flags; /* Collection of OR-ed bits that control - * the evaluation of the script. Only - * TCL_EVAL_GLOBAL and TCL_EVAL_INVOKE - * are currently supported. */ + int flags; /* Collection of OR-ed bits that control the + * evaluation of the script. Only + * TCL_EVAL_GLOBAL and TCL_EVAL_INVOKE are + * currently supported. */ { Interp *iPtr = (Interp *)interp; Trace *tracePtr; @@ -3509,7 +3513,7 @@ Tcl_EvalObjv(interp, objc, objv, flags) for (tracePtr = iPtr->tracePtr; tracePtr; tracePtr = tracePtr->nextPtr) { if ((tracePtr->level == 0) || (iPtr->numLevels <= tracePtr->level)) { /* - * The command may be needed for an execution trace. Generate a + * The command may be needed for an execution trace. Generate a * command string. */ @@ -3528,8 +3532,8 @@ Tcl_EvalObjv(interp, objc, objv, flags) iPtr->numLevels--; /* - * If we are again at the top level, process any unusual - * return code returned by the evaluated code. + * If we are again at the top level, process any unusual return code + * returned by the evaluated code. */ if (iPtr->numLevels == 0) { @@ -3545,8 +3549,8 @@ Tcl_EvalObjv(interp, objc, objv, flags) if ((code == TCL_ERROR) && !(flags & TCL_EVAL_INVOKE)) { - /* - * If there was an error, a command string will be needed for the + /* + * If there was an error, a command string will be needed for the * error log: generate it now if it was not done previously. */ @@ -3572,16 +3576,16 @@ Tcl_EvalObjv(interp, objc, objv, flags) * * Tcl_LogCommandInfo -- * - * This procedure is invoked after an error occurs in an interpreter. - * It adds information to iPtr->errorInfo field to describe the - * command that was being executed when the error occurred. + * This procedure is invoked after an error occurs in an interpreter. It + * adds information to iPtr->errorInfo field to describe the command that + * was being executed when the error occurred. * * Results: * None. * * Side effects: - * Information about the command is added to errorInfo and the - * line number stored internally in the interpreter is set. + * Information about the command is added to errorInfo and the line + * number stored internally in the interpreter is set. * *---------------------------------------------------------------------- */ @@ -3591,10 +3595,10 @@ Tcl_LogCommandInfo(interp, script, command, length) Tcl_Interp *interp; /* Interpreter in which to log information. */ CONST char *script; /* First character in script containing * command (must be <= command). */ - CONST char *command; /* First character in command that - * generated the error. */ - int length; /* Number of bytes in command (-1 means - * use all bytes up to first null byte). */ + CONST char *command; /* First character in command that generated + * the error. */ + int length; /* Number of bytes in command (-1 means use + * all bytes up to first null byte). */ { register CONST char *p; Interp *iPtr = (Interp *) interp; @@ -3602,8 +3606,8 @@ Tcl_LogCommandInfo(interp, script, command, length) if (iPtr->flags & ERR_ALREADY_LOGGED) { /* - * Someone else has already logged error information for this - * command; we shouldn't add anything more. + * Someone else has already logged error information for this command; + * we shouldn't add anything more. */ return; @@ -3637,15 +3641,14 @@ Tcl_LogCommandInfo(interp, script, command, length) * * Tcl_EvalTokensStandard -- * - * Given an array of tokens parsed from a Tcl command (e.g., the - * tokens that make up a word or the index for an array variable) - * this procedure evaluates the tokens and concatenates their - * values to form a single result value. - * + * Given an array of tokens parsed from a Tcl command (e.g., the tokens + * that make up a word or the index for an array variable) this procedure + * evaluates the tokens and concatenates their values to form a single + * result value. + * * Results: - * The return value is a standard Tcl completion code such as - * TCL_OK or TCL_ERROR. A result or error message is left in - * interp's result. + * The return value is a standard Tcl completion code such as TCL_OK or + * TCL_ERROR. A result or error message is left in interp's result. * * Side effects: * Depends on the array of tokens being evaled. @@ -3655,11 +3658,11 @@ Tcl_LogCommandInfo(interp, script, command, length) int Tcl_EvalTokensStandard(interp, tokenPtr, count) - Tcl_Interp *interp; /* Interpreter in which to lookup - * variables, execute nested commands, - * and report errors. */ - Tcl_Token *tokenPtr; /* Pointer to first in an array of tokens - * to evaluate and concatenate. */ + Tcl_Interp *interp; /* Interpreter in which to lookup variables, + * execute nested commands, and report + * errors. */ + Tcl_Token *tokenPtr; /* Pointer to first in an array of tokens to + * evaluate and concatenate. */ int count; /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ { @@ -3672,35 +3675,35 @@ Tcl_EvalTokensStandard(interp, tokenPtr, count) * * Tcl_EvalTokens -- * - * Given an array of tokens parsed from a Tcl command (e.g., the - * tokens that make up a word or the index for an array variable) - * this procedure evaluates the tokens and concatenates their - * values to form a single result value. + * Given an array of tokens parsed from a Tcl command (e.g., the tokens + * that make up a word or the index for an array variable) this procedure + * evaluates the tokens and concatenates their values to form a single + * result value. * * Results: - * The return value is a pointer to a newly allocated Tcl_Obj - * containing the value of the array of tokens. The reference - * count of the returned object has been incremented. If an error - * occurs in evaluating the tokens then a NULL value is returned - * and an error message is left in interp's result. + * The return value is a pointer to a newly allocated Tcl_Obj containing + * the value of the array of tokens. The reference count of the returned + * object has been incremented. If an error occurs in evaluating the + * tokens then a NULL value is returned and an error message is left in + * interp's result. * * Side effects: * A new object is allocated to hold the result. * *---------------------------------------------------------------------- * - * This uses a non-standard return convention; its use is now deprecated. - * It is a wrapper for the new function Tcl_EvalTokensStandard, and is not - * used in the core any longer. It is only kept for backward compatibility. + * This uses a non-standard return convention; its use is now deprecated. It + * is a wrapper for the new function Tcl_EvalTokensStandard, and is not used + * in the core any longer. It is only kept for backward compatibility. */ Tcl_Obj * Tcl_EvalTokens(interp, tokenPtr, count) - Tcl_Interp *interp; /* Interpreter in which to lookup - * variables, execute nested commands, - * and report errors. */ - Tcl_Token *tokenPtr; /* Pointer to first in an array of tokens - * to evaluate and concatenate. */ + Tcl_Interp *interp; /* Interpreter in which to lookup variables, + * execute nested commands, and report + * errors. */ + Tcl_Token *tokenPtr; /* Pointer to first in an array of tokens to + * evaluate and concatenate. */ int count; /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ { @@ -3724,15 +3727,14 @@ Tcl_EvalTokens(interp, tokenPtr, count) * * Tcl_EvalEx -- * - * This procedure evaluates a Tcl script without using the compiler - * or byte-code interpreter. It just parses the script, creates - * values for each word of each command, then calls EvalObjv - * to execute each command. + * This procedure evaluates a Tcl script without using the compiler or + * byte-code interpreter. It just parses the script, creates values for + * each word of each command, then calls EvalObjv to execute each + * command. * * Results: - * The return value is a standard Tcl completion code such as - * TCL_OK or TCL_ERROR. A result or error message is left in - * interp's result. + * The return value is a standard Tcl completion code such as TCL_OK or + * TCL_ERROR. A result or error message is left in interp's result. * * Side effects: * Depends on the script. @@ -3743,15 +3745,14 @@ Tcl_EvalTokens(interp, tokenPtr, count) int Tcl_EvalEx(interp, script, numBytes, flags) Tcl_Interp *interp; /* Interpreter in which to evaluate the - * script. Also used for error reporting. */ + * script. Also used for error reporting. */ CONST char *script; /* First character of script to evaluate. */ - int numBytes; /* Number of bytes in script. If < 0, the + int numBytes; /* Number of bytes in script. If < 0, the * script consists of all bytes up to the * first null character. */ - int flags; /* Collection of OR-ed bits that control - * the evaluation of the script. Only - * TCL_EVAL_GLOBAL is currently - * supported. */ + int flags; /* Collection of OR-ed bits that control the + * evaluation of the script. Only + * TCL_EVAL_GLOBAL is currently supported. */ { Interp *iPtr = (Interp *) interp; CONST char *p, *next; @@ -3761,14 +3762,14 @@ Tcl_EvalEx(interp, script, numBytes, flags) int expandStatic[NUM_STATIC_OBJS], *expand; Tcl_Token *tokenPtr; int i, code, commandLength, bytesLeft, expandRequested; - CallFrame *savedVarFramePtr; /* Saves old copy of iPtr->varFramePtr - * in case TCL_EVAL_GLOBAL was set. */ + CallFrame *savedVarFramePtr;/* Saves old copy of iPtr->varFramePtr in case + * TCL_EVAL_GLOBAL was set. */ int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); /* - * The variables below keep track of how much state has been - * allocated while evaluating the script, so that it can be freed - * properly if an error occurs. + * The variables below keep track of how much state has been allocated + * while evaluating the script, so that it can be freed properly if an + * error occurs. */ int gotParse = 0, objectsUsed = 0; @@ -3784,8 +3785,8 @@ Tcl_EvalEx(interp, script, numBytes, flags) } /* - * Each iteration through the following loop parses the next - * command from the script and then executes it. + * Each iteration through the following loop parses the next command from + * the script and then executes it. */ objv = objvSpace = staticObjArray; @@ -3798,25 +3799,26 @@ Tcl_EvalEx(interp, script, numBytes, flags) code = TCL_ERROR; goto error; } - gotParse = 1; + gotParse = 1; if (parse.numWords > 0) { /* * Generate an array of objects for the words of the command. */ + int objectsNeeded = 0; if (parse.numWords > NUM_STATIC_OBJS) { - expand = (int *) ckalloc((unsigned) - (parse.numWords * sizeof(int))); - objvSpace = (Tcl_Obj **) ckalloc((unsigned) - (parse.numWords * sizeof(Tcl_Obj *))); + expand = (int *) + ckalloc((unsigned) (parse.numWords * sizeof(int))); + objvSpace = (Tcl_Obj **) + ckalloc((unsigned) (parse.numWords*sizeof(Tcl_Obj *))); } expandRequested = 0; objv = objvSpace; for (objectsUsed = 0, tokenPtr = parse.tokenPtr; objectsUsed < parse.numWords; objectsUsed++, tokenPtr += (tokenPtr->numComponents + 1)) { - code = TclSubstTokens(interp, tokenPtr+1, + code = TclSubstTokens(interp, tokenPtr+1, tokenPtr->numComponents, NULL); if (code != TCL_OK) { goto error; @@ -3829,9 +3831,13 @@ Tcl_EvalEx(interp, script, numBytes, flags) code = Tcl_ListObjLength(interp, objv[objectsUsed], &numElements); if (code == TCL_ERROR) { - /* Attempt to expand a non-list */ + /* + * Attempt to expand a non-list. + */ + Tcl_Obj *msg; Tcl_Obj *wordNum; + msg = Tcl_NewStringObj("\n (expanding word ", -1); TclNewIntObj(wordNum, objectsUsed); Tcl_IncrRefCount(wordNum); @@ -3853,7 +3859,10 @@ Tcl_EvalEx(interp, script, numBytes, flags) } } if (expandRequested) { - /* Some word expansion was requested. Check for objv resize */ + /* + * Some word expansion was requested. Check for objv resize. + */ + Tcl_Obj **copy = objvSpace; int wordIdx = parse.numWords; int objIdx = objectsNeeded - 1; @@ -3869,6 +3878,7 @@ Tcl_EvalEx(interp, script, numBytes, flags) if (expand[wordIdx]) { int numElements; Tcl_Obj **elements, *temp = copy[wordIdx]; + Tcl_ListObjGetElements(NULL, temp, &numElements, &elements); objectsUsed += numElements; @@ -3893,8 +3903,8 @@ Tcl_EvalEx(interp, script, numBytes, flags) * Execute the command and free the objects for its words. */ - iPtr->numLevels++; - code = TclEvalObjvInternal(interp, objectsUsed, objv, + iPtr->numLevels++; + code = TclEvalObjvInternal(interp, objectsUsed, objv, parse.commandStart, parse.commandSize, 0); iPtr->numLevels--; if (code != TCL_OK) { @@ -3908,10 +3918,12 @@ Tcl_EvalEx(interp, script, numBytes, flags) ckfree((char *) objvSpace); objvSpace = staticObjArray; } - /* + + /* * Free expand separately since objvSpace could have been - * reallocated above. + * reallocated above. */ + if (expand != expandStatic) { ckfree((char *) expand); expand = expandStatic; @@ -3931,18 +3943,20 @@ Tcl_EvalEx(interp, script, numBytes, flags) iPtr->varFramePtr = savedVarFramePtr; return TCL_OK; - error: - /* Generate and log various pieces of error information. */ - if (iPtr->numLevels == 0) { - if (code == TCL_RETURN) { - code = TclUpdateReturnInfo(iPtr); - } - if ((code != TCL_OK) && (code != TCL_ERROR) && !allowExceptions) { - ProcessUnexpectedResult(interp, code); - code = TCL_ERROR; - } + error: + /* + * Generate and log various pieces of error information. + */ + if (iPtr->numLevels == 0) { + if (code == TCL_RETURN) { + code = TclUpdateReturnInfo(iPtr); } - if ((code == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { + if ((code != TCL_OK) && (code != TCL_ERROR) && !allowExceptions) { + ProcessUnexpectedResult(interp, code); + code = TCL_ERROR; + } + } + if ((code == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { commandLength = parse.commandSize; if (parse.term == parse.commandStart + commandLength - 1) { /* @@ -3958,7 +3972,9 @@ Tcl_EvalEx(interp, script, numBytes, flags) } iPtr->flags &= ~ERR_ALREADY_LOGGED; - /* Then free resources that had been allocated to the command. */ + /* + * Then free resources that had been allocated to the command. + */ for (i = 0; i < objectsUsed; i++) { Tcl_DecrRefCount(objv[i]); @@ -3981,18 +3997,16 @@ Tcl_EvalEx(interp, script, numBytes, flags) * * Tcl_Eval -- * - * Execute a Tcl command in a string. This procedure executes the - * script directly, rather than compiling it to bytecodes. Before - * the arrival of the bytecode compiler in Tcl 8.0 Tcl_Eval was - * the main procedure used for executing Tcl commands, but nowadays - * it isn't used much. + * Execute a Tcl command in a string. This procedure executes the script + * directly, rather than compiling it to bytecodes. Before the arrival of + * the bytecode compiler in Tcl 8.0 Tcl_Eval was the main procedure used + * for executing Tcl commands, but nowadays it isn't used much. * * Results: - * The return value is one of the return codes defined in tcl.h - * (such as TCL_OK), and interp's result contains a value - * to supplement the return code. The value of the result - * will persist only until the next call to Tcl_Eval or Tcl_EvalObj: - * you must copy it or lose it! + * The return value is one of the return codes defined in tcl.h (such as + * TCL_OK), and interp's result contains a value to supplement the return + * code. The value of the result will persist only until the next call to + * Tcl_Eval or Tcl_EvalObj: you must copy it or lose it! * * Side effects: * Can be almost arbitrary, depending on the commands in the script. @@ -4002,16 +4016,16 @@ Tcl_EvalEx(interp, script, numBytes, flags) int Tcl_Eval(interp, script) - Tcl_Interp *interp; /* Token for command interpreter (returned - * by previous call to Tcl_CreateInterp). */ + Tcl_Interp *interp; /* Token for command interpreter (returned by + * previous call to Tcl_CreateInterp). */ CONST char *script; /* Pointer to TCL command to execute. */ { int code = Tcl_EvalEx(interp, script, -1, 0); /* - * For backwards compatibility with old C code that predates the - * object system in Tcl 8.0, we have to mirror the object result - * back into the string result (some callers may expect it there). + * For backwards compatibility with old C code that predates the object + * system in Tcl 8.0, we have to mirror the object result back into the + * string result (some callers may expect it there). */ (void) Tcl_GetStringResult(interp); @@ -4059,42 +4073,38 @@ Tcl_GlobalEvalObj(interp, objPtr) * Tcl_EvalObjEx -- * * Execute Tcl commands stored in a Tcl object. These commands are - * compiled into bytecodes if necessary, unless TCL_EVAL_DIRECT - * is specified. + * compiled into bytecodes if necessary, unless TCL_EVAL_DIRECT is + * specified. * * Results: - * The return value is one of the return codes defined in tcl.h - * (such as TCL_OK), and the interpreter's result contains a value - * to supplement the return code. + * The return value is one of the return codes defined in tcl.h (such as + * TCL_OK), and the interpreter's result contains a value to supplement + * the return code. * * Side effects: - * The object is converted, if necessary, to a ByteCode object that - * holds the bytecode instructions for the commands. Executing the - * commands will almost certainly have side effects that depend - * on those commands. + * The object is converted, if necessary, to a ByteCode object that holds + * the bytecode instructions for the commands. Executing the commands + * will almost certainly have side effects that depend on those commands. * *---------------------------------------------------------------------- */ int Tcl_EvalObjEx(interp, objPtr, flags) - Tcl_Interp *interp; /* Token for command interpreter - * (returned by a previous call to - * Tcl_CreateInterp). */ - register Tcl_Obj *objPtr; /* Pointer to object containing - * commands to execute. */ - int flags; /* Collection of OR-ed bits that - * control the evaluation of the - * script. Supported values are - * TCL_EVAL_GLOBAL and - * TCL_EVAL_DIRECT. */ + Tcl_Interp *interp; /* Token for command interpreter (returned by + * a previous call to Tcl_CreateInterp). */ + register Tcl_Obj *objPtr; /* Pointer to object containing commands to + * execute. */ + int flags; /* Collection of OR-ed bits that control the + * evaluation of the script. Supported values + * are TCL_EVAL_GLOBAL and TCL_EVAL_DIRECT. */ { register Interp *iPtr = (Interp *) interp; char *script; int numSrcBytes; int result; - CallFrame *savedVarFramePtr; /* Saves old copy of iPtr->varFramePtr - * in case TCL_EVAL_GLOBAL was set. */ + CallFrame *savedVarFramePtr;/* Saves old copy of iPtr->varFramePtr in case + * TCL_EVAL_GLOBAL was set. */ int allowExceptions = (iPtr->evalFlags & TCL_ALLOW_EXCEPTIONS); Tcl_IncrRefCount(objPtr); @@ -4102,46 +4112,58 @@ Tcl_EvalObjEx(interp, objPtr, flags) if (flags & TCL_EVAL_DIRECT) { /* * We're not supposed to use the compiler or byte-code interpreter. - * Let Tcl_EvalEx evaluate the command directly (and probably - * more slowly). + * Let Tcl_EvalEx evaluate the command directly (and probably more + * slowly). + * + * Pure List Optimization (no string representation). In this case, we + * can safely use Tcl_EvalObjv instead and get an appreciable + * improvement in execution speed. This is because it allows us to + * avoid a setFromAny step that would just pack everything into a + * string and back out again. * - * Pure List Optimization (no string representation). In this - * case, we can safely use Tcl_EvalObjv instead and get an - * appreciable improvement in execution speed. This is because it - * allows us to avoid a setFromAny step that would just pack - * everything into a string and back out again. + * This restriction has been relaxed a bit by storing in lists whether + * they are "canonical" or not (a canonical list being one that is + * either pure or that has its string rep derived by + * UpdateStringOfList from the internal rep). */ - if ((objPtr->typePtr == &tclListType) && /* is a list... */ - (objPtr->bytes == NULL) /* ...without a string rep */) { - List *listRepPtr; - /* - * Increase the reference count of the List structure, to avoid a - * segfault if objPtr loses its List internal rep [Bug 1119369] - */ + if (objPtr->typePtr == &tclListType) { /* is a list... */ + List *listRepPtr; listRepPtr = (List *) objPtr->internalRep.twoPtrValue.ptr1; - listRepPtr->refCount++; - result = Tcl_EvalObjv(interp, listRepPtr->elemCount, - &listRepPtr->elements, flags); + if (objPtr->bytes == NULL || /* ...without a string rep */ + listRepPtr->canonicalFlag) {/* ...or that is canonical */ - /* - * If we are the last users of listRepPtr, free it. - */ + /* + * Increase the reference count of the List structure, to + * avoid a segfault if objPtr loses its List internal rep [Bug + * 1119369] + */ + + listRepPtr->refCount++; + + result = Tcl_EvalObjv(interp, listRepPtr->elemCount, + &listRepPtr->elements, flags); + + /* + * If we are the last users of listRepPtr, free it. + */ + + if (--listRepPtr->refCount <= 0) { + int i, elemCount = listRepPtr->elemCount; + Tcl_Obj **elements = &listRepPtr->elements; - if (--listRepPtr->refCount <= 0) { - int i, elemCount = listRepPtr->elemCount; - Tcl_Obj **elements = &listRepPtr->elements; - for (i=0; inumLevels == 0) { if (result == TCL_RETURN) { result = TclUpdateReturnInfo(iPtr); } - if ((result != TCL_OK) && (result != TCL_ERROR) + if ((result != TCL_OK) && (result != TCL_ERROR) && !allowExceptions) { ProcessUnexpectedResult(interp, result); result = TCL_ERROR; @@ -4172,9 +4194,10 @@ Tcl_EvalObjEx(interp, objPtr, flags) } } iPtr->evalFlags = 0; - iPtr->varFramePtr = savedVarFramePtr; + iPtr->varFramePtr = savedVarFramePtr; } + done: TclDecrRefCount(objPtr); return result; } @@ -4184,17 +4207,17 @@ Tcl_EvalObjEx(interp, objPtr, flags) * * ProcessUnexpectedResult -- * - * Procedure called by Tcl_EvalObj to set the interpreter's result - * value to an appropriate error message when the code it evaluates - * returns an unexpected result code (not TCL_OK and not TCL_ERROR) to - * the topmost evaluation level. + * Procedure called by Tcl_EvalObj to set the interpreter's result value + * to an appropriate error message when the code it evaluates returns an + * unexpected result code (not TCL_OK and not TCL_ERROR) to the topmost + * evaluation level. * * Results: * None. * * Side effects: - * The interpreter result is set to an error message appropriate to - * the result code. + * The interpreter result is set to an error message appropriate to the + * result code. * *---------------------------------------------------------------------- */ @@ -4231,9 +4254,9 @@ ProcessUnexpectedResult(interp, returnCode) * Results: * Each of the procedures below returns a standard Tcl result. If an * error occurs then an error message is left in the interp's result. - * Otherwise the value of the expression, in the appropriate form, - * is stored at *ptr. If the expression had a result that was - * incompatible with the desired form then an error is returned. + * Otherwise the value of the expression, in the appropriate form, is + * stored at *ptr. If the expression had a result that was incompatible + * with the desired form then an error is returned. * * Side effects: * None. @@ -4245,7 +4268,7 @@ int Tcl_ExprLong(interp, exprstring, ptr) Tcl_Interp *interp; /* Context in which to evaluate the * expression. */ - CONST char *exprstring; /* Expression to evaluate. */ + CONST char *exprstring; /* Expression to evaluate. */ long *ptr; /* Where to store result. */ { register Tcl_Obj *exprPtr; @@ -4269,7 +4292,7 @@ int Tcl_ExprDouble(interp, exprstring, ptr) Tcl_Interp *interp; /* Context in which to evaluate the * expression. */ - CONST char *exprstring; /* Expression to evaluate. */ + CONST char *exprstring; /* Expression to evaluate. */ double *ptr; /* Where to store result. */ { register Tcl_Obj *exprPtr; @@ -4307,13 +4330,14 @@ Tcl_ExprBoolean(interp, exprstring, ptr) } else { int result; Tcl_Obj *exprPtr = Tcl_NewStringObj(exprstring, -1); + Tcl_IncrRefCount(exprPtr); result = Tcl_ExprBooleanObj(interp, exprPtr, ptr); Tcl_DecrRefCount(exprPtr); if (result != TCL_OK) { /* - * Move the interpreter's object result to the string result, - * then reset the object result. + * Move the interpreter's object result to the string result, then + * reset the object result. */ (void) Tcl_GetStringResult(interp); @@ -4327,16 +4351,15 @@ Tcl_ExprBoolean(interp, exprstring, ptr) * * Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj -- * - * Procedures to evaluate an expression in an object and return its - * value in a particular form. + * Procedures to evaluate an expression in an object and return its value + * in a particular form. * * Results: - * Each of the procedures below returns a standard Tcl result - * object. If an error occurs then an error message is left in the - * interpreter's result. Otherwise the value of the expression, in the - * appropriate form, is stored at *ptr. If the expression had a result - * that was incompatible with the desired form then an error is - * returned. + * Each of the procedures below returns a standard Tcl result object. If + * an error occurs then an error message is left in the interpreter's + * result. Otherwise the value of the expression, in the appropriate + * form, is stored at *ptr. If the expression had a result that was + * incompatible with the desired form then an error is returned. * * Side effects: * None. @@ -4346,10 +4369,10 @@ Tcl_ExprBoolean(interp, exprstring, ptr) int Tcl_ExprLongObj(interp, objPtr, ptr) - Tcl_Interp *interp; /* Context in which to evaluate the - * expression. */ - register Tcl_Obj *objPtr; /* Expression to evaluate. */ - long *ptr; /* Where to store long result. */ + Tcl_Interp *interp; /* Context in which to evaluate the + * expression. */ + register Tcl_Obj *objPtr; /* Expression to evaluate. */ + long *ptr; /* Where to store long result. */ { Tcl_Obj *resultPtr; int result; @@ -4381,10 +4404,10 @@ Tcl_ExprLongObj(interp, objPtr, ptr) int Tcl_ExprDoubleObj(interp, objPtr, ptr) - Tcl_Interp *interp; /* Context in which to evaluate the - * expression. */ - register Tcl_Obj *objPtr; /* Expression to evaluate. */ - double *ptr; /* Where to store double result. */ + Tcl_Interp *interp; /* Context in which to evaluate the + * expression. */ + register Tcl_Obj *objPtr; /* Expression to evaluate. */ + double *ptr; /* Where to store double result. */ { Tcl_Obj *resultPtr; int result; @@ -4411,10 +4434,10 @@ Tcl_ExprDoubleObj(interp, objPtr, ptr) int Tcl_ExprBooleanObj(interp, objPtr, ptr) - Tcl_Interp *interp; /* Context in which to evaluate the - * expression. */ - register Tcl_Obj *objPtr; /* Expression to evaluate. */ - int *ptr; /* Where to store 0/1 result. */ + Tcl_Interp *interp; /* Context in which to evaluate the + * expression. */ + register Tcl_Obj *objPtr; /* Expression to evaluate. */ + int *ptr; /* Where to store 0/1 result. */ { Tcl_Obj *resultPtr; int result; @@ -4432,12 +4455,11 @@ Tcl_ExprBooleanObj(interp, objPtr, ptr) * * TclObjInvokeNamespace -- * - * Object version: Invokes a Tcl command, given an objv/objc, from - * either the exposed or hidden set of commands in the given - * interpreter. + * Object version: Invokes a Tcl command, given an objv/objc, from either + * the exposed or hidden set of commands in the given interpreter. * NOTE: The command is invoked in the global stack frame of the - * interpreter or namespace, thus it cannot see any current state on - * the stack of that interpreter. + * interpreter or namespace, thus it cannot see any current state on the + * stack of that interpreter. * * Results: * A standard Tcl result. @@ -4456,17 +4478,16 @@ TclObjInvokeNamespace(interp, objc, objv, nsPtr, flags) Tcl_Obj *CONST objv[]; /* Argument objects; objv[0] points to the * name of the command to invoke. */ Tcl_Namespace *nsPtr; /* The namespace to use. */ - int flags; /* Combination of flags controlling the - * call: TCL_INVOKE_HIDDEN, - * TCL_INVOKE_NO_UNKNOWN, or - * TCL_INVOKE_NO_TRACEBACK. */ + int flags; /* Combination of flags controlling the call: + * TCL_INVOKE_HIDDEN, TCL_INVOKE_NO_UNKNOWN, + * or TCL_INVOKE_NO_TRACEBACK. */ { int result; Tcl_CallFrame *framePtr; /* - * Make the specified namespace the current namespace and invoke - * the command. + * Make the specified namespace the current namespace and invoke the + * command. */ result = TclPushStackFrame(interp, &framePtr, nsPtr, /*isProcCallFrame*/ 0); @@ -4485,8 +4506,8 @@ TclObjInvokeNamespace(interp, objc, objv, nsPtr, flags) * * TclObjInvoke -- * - * Invokes a Tcl command, given an objv/objc, from either the - * exposed or the hidden sets of commands in the given interpreter. + * Invokes a Tcl command, given an objv/objc, from either the exposed or + * the hidden sets of commands in the given interpreter. * * Results: * A standard Tcl object result. @@ -4504,10 +4525,9 @@ TclObjInvoke(interp, objc, objv, flags) int objc; /* Count of arguments. */ Tcl_Obj *CONST objv[]; /* Argument objects; objv[0] points to the * name of the command to invoke. */ - int flags; /* Combination of flags controlling the - * call: TCL_INVOKE_HIDDEN, - * TCL_INVOKE_NO_UNKNOWN, or - * TCL_INVOKE_NO_TRACEBACK. */ + int flags; /* Combination of flags controlling the call: + * TCL_INVOKE_HIDDEN, TCL_INVOKE_NO_UNKNOWN, + * or TCL_INVOKE_NO_TRACEBACK. */ { register Interp *iPtr = (Interp *) interp; Tcl_HashTable *hTblPtr; /* Table of hidden commands. */ @@ -4545,14 +4565,16 @@ TclObjInvoke(interp, objc, objv, flags) } cmdPtr = (Command *) Tcl_GetHashValue(hPtr); - /* Invoke the command procedure. */ + /* + * Invoke the command procedure. + */ iPtr->cmdCount++; result = (*cmdPtr->objProc)(cmdPtr->objClientData, interp, objc, objv); /* - * If an error occurred, record information about what was being - * executed when the error occurred. + * If an error occurred, record information about what was being executed + * when the error occurred. */ if ((result == TCL_ERROR) @@ -4561,6 +4583,7 @@ TclObjInvoke(interp, objc, objv, flags) int length; Tcl_Obj *command = Tcl_NewListObj(objc, objv); CONST char* cmdString; + Tcl_IncrRefCount(command); cmdString = Tcl_GetStringFromObj(command, &length); Tcl_LogCommandInfo(interp, cmdString, cmdString, length); @@ -4580,13 +4603,12 @@ TclObjInvoke(interp, objc, objv, flags) * * Results: * A standard Tcl result. If the result is TCL_OK, then the interp's - * result is set to the string value of the expression. If the result - * is TCL_ERROR, then the interp's result contains an error message. + * result is set to the string value of the expression. If the result is + * TCL_ERROR, then the interp's result contains an error message. * * Side effects: * A Tcl object is allocated to hold a copy of the expression string. - * This expression object is passed to Tcl_ExprObj and then - * deallocated. + * This expression object is passed to Tcl_ExprObj and then deallocated. * *--------------------------------------------------------------------------- */ @@ -4598,11 +4620,16 @@ Tcl_ExprString(interp, expr) CONST char *expr; /* Expression to evaluate. */ { int code = TCL_OK; + if (expr[0] == '\0') { - /* An empty string. Just set the interpreter's result to 0. */ + /* + * An empty string. Just set the interpreter's result to 0. + */ + Tcl_SetResult(interp, "0", TCL_VOLATILE); } else { Tcl_Obj *resultPtr, *exprObj = Tcl_NewStringObj(expr, -1); + Tcl_IncrRefCount(exprObj); code = Tcl_ExprObj(interp, exprObj, &resultPtr); Tcl_DecrRefCount(exprObj); @@ -4611,7 +4638,10 @@ Tcl_ExprString(interp, expr) Tcl_DecrRefCount(resultPtr); } - /* Force the string rep of the interp result */ + /* + * Force the string rep of the interp result. + */ + (void) Tcl_GetStringResult(interp); } return code; @@ -4622,16 +4652,16 @@ Tcl_ExprString(interp, expr) * * TclAppendObjToErrorInfo -- * - * Add a Tcl_Obj value to the errorInfo field that describes the - * current error. + * Add a Tcl_Obj value to the errorInfo field that describes the current + * error. * * Results: * None. * * Side effects: - * The value of the Tcl_obj is appended to the errorInfo field. - * If we are just starting to log an error, errorInfo is initialized - * from the error message in the interpreter's result. + * The value of the Tcl_obj is appended to the errorInfo field. If we are + * just starting to log an error, errorInfo is initialized from the error + * message in the interpreter's result. * *---------------------------------------------------------------------- */ @@ -4644,6 +4674,7 @@ TclAppendObjToErrorInfo(interp, objPtr) { int length; CONST char *message = Tcl_GetStringFromObj(objPtr, &length); + Tcl_AddObjErrorInfo(interp, message, length); } @@ -4652,16 +4683,16 @@ TclAppendObjToErrorInfo(interp, objPtr) * * Tcl_AddErrorInfo -- * - * Add information to the errorInfo field that describes the - * current error. + * Add information to the errorInfo field that describes the current + * error. * * Results: * None. * * Side effects: - * The contents of message are appended to the errorInfo field. - * If we are just starting to log an error, errorInfo is initialized - * from the error message in the interpreter's result. + * The contents of message are appended to the errorInfo field. If we are + * just starting to log an error, errorInfo is initialized from the error + * message in the interpreter's result. * *---------------------------------------------------------------------- */ @@ -4680,18 +4711,18 @@ Tcl_AddErrorInfo(interp, message) * * Tcl_AddObjErrorInfo -- * - * Add information to the errorInfo field that describes the - * current error. This routine differs from Tcl_AddErrorInfo by - * taking a byte pointer and length. + * Add information to the errorInfo field that describes the current + * error. This routine differs from Tcl_AddErrorInfo by taking a byte + * pointer and length. * * Results: * None. * * Side effects: - * "length" bytes from "message" are appended to the errorInfo field. - * If "length" is negative, use bytes up to the first NULL byte. - * If we are just starting to log an error, errorInfo is initialized - * from the error message in the interpreter's result. + * "length" bytes from "message" are appended to the errorInfo field. If + * "length" is negative, use bytes up to the first NULL byte. If we are + * just starting to log an error, errorInfo is initialized from the error + * message in the interpreter's result. * *---------------------------------------------------------------------- */ @@ -4702,26 +4733,26 @@ Tcl_AddObjErrorInfo(interp, message, length) * pertains. */ CONST char *message; /* Points to the first byte of an array of * bytes of the message. */ - int length; /* The number of bytes in the message. - * If < 0, then append all bytes up to a - * NULL byte. */ + int length; /* The number of bytes in the message. If < 0, + * then append all bytes up to a NULL byte. */ { register Interp *iPtr = (Interp *) interp; /* - * If we are just starting to log an error, errorInfo is initialized - * from the error message in the interpreter's result. + * If we are just starting to log an error, errorInfo is initialized from + * the error message in the interpreter's result. */ if (iPtr->errorInfo == NULL) { /* just starting to log error */ if (iPtr->result[0] != 0) { /* - * The interp's string result is set, apparently by some - * extension making a deprecated direct write to it. - * That extension may expect interp->result to continue - * to be set, so we'll take special pains to avoid clearing - * it, until we drop support for interp->result completely. + * The interp's string result is set, apparently by some extension + * making a deprecated direct write to it. That extension may + * expect interp->result to continue to be set, so we'll take + * special pains to avoid clearing it, until we drop support for + * interp->result completely. */ + iPtr->errorInfo = Tcl_NewStringObj(interp->result, -1); } else { iPtr->errorInfo = iPtr->objResultPtr; @@ -4751,12 +4782,12 @@ Tcl_AddObjErrorInfo(interp, message, length) * * Tcl_VarEvalVA -- * - * Given a variable number of string arguments, concatenate them - * all together and execute the result as a Tcl command. + * Given a variable number of string arguments, concatenate them all + * together and execute the result as a Tcl command. * * Results: - * A standard Tcl return result. An error message or other result may - * be left in the interp's result. + * A standard Tcl return result. An error message or other result may be + * left in the interp's result. * * Side effects: * Depends on what was done by the command. @@ -4774,10 +4805,9 @@ Tcl_VarEvalVA(interp, argList) int result; /* - * Copy the strings one after the other into a single larger - * string. Use stack-allocated space for small commands, but if - * the command gets too large than call ckalloc to create the - * space. + * Copy the strings one after the other into a single larger string. Use + * stack-allocated space for small commands, but if the command gets too + * large than call ckalloc to create the space. */ Tcl_DStringInit(&buf); @@ -4799,12 +4829,12 @@ Tcl_VarEvalVA(interp, argList) * * Tcl_VarEval -- * - * Given a variable number of string arguments, concatenate them - * all together and execute the result as a Tcl command. + * Given a variable number of string arguments, concatenate them all + * together and execute the result as a Tcl command. * * Results: - * A standard Tcl return result. An error message or other - * result may be left in interp->result. + * A standard Tcl return result. An error message or other result may be + * left in interp->result. * * Side effects: * Depends on what was done by the command. @@ -4834,14 +4864,13 @@ Tcl_VarEval TCL_VARARGS_DEF(Tcl_Interp *,arg1) * Evaluate a command at global level in an interpreter. * * Results: - * A standard Tcl result is returned, and the interp's result is - * modified accordingly. + * A standard Tcl result is returned, and the interp's result is modified + * accordingly. * * Side effects: - * The command string is executed in interp, and the execution - * is carried out in the variable context of global level (no - * procedures active), just as if an "uplevel #0" command were - * being executed. + * The command string is executed in interp, and the execution is carried + * out in the variable context of global level (no procedures active), + * just as if an "uplevel #0" command were being executed. * --------------------------------------------------------------------------- */ @@ -4867,8 +4896,8 @@ Tcl_GlobalEval(interp, command) * * Tcl_SetRecursionLimit -- * - * Set the maximum number of recursive calls that may be active - * for an interpreter at once. + * Set the maximum number of recursive calls that may be active for an + * interpreter at once. * * Results: * The return value is the old limit on nesting for interp. @@ -4881,9 +4910,9 @@ Tcl_GlobalEval(interp, command) int Tcl_SetRecursionLimit(interp, depth) - Tcl_Interp *interp; /* Interpreter whose nesting limit - * is to be set. */ - int depth; /* New value for maximimum depth. */ + Tcl_Interp *interp; /* Interpreter whose nesting limit is to be + * set. */ + int depth; /* New value for maximimum depth. */ { Interp *iPtr = (Interp *) interp; int old; @@ -4900,17 +4929,15 @@ Tcl_SetRecursionLimit(interp, depth) * * Tcl_AllowExceptions -- * - * Sets a flag in an interpreter so that exceptions can occur - * in the next call to Tcl_Eval without them being turned into - * errors. + * Sets a flag in an interpreter so that exceptions can occur in the next + * call to Tcl_Eval without them being turned into errors. * * Results: * None. * * Side effects: - * The TCL_ALLOW_EXCEPTIONS flag gets set in the interpreter's - * evalFlags structure. See the reference documentation for - * more details. + * The TCL_ALLOW_EXCEPTIONS flag gets set in the interpreter's evalFlags + * structure. See the reference documentation for more details. * *---------------------------------------------------------------------- */ @@ -4923,16 +4950,15 @@ Tcl_AllowExceptions(interp) iPtr->evalFlags |= TCL_ALLOW_EXCEPTIONS; } - /* *---------------------------------------------------------------------- * * Tcl_GetVersion -- * - * Get the Tcl major, minor, and patchlevel version numbers and - * the release type. A patch is a release type TCL_FINAL_RELEASE - * with a patchLevel > 0. + * Get the Tcl major, minor, and patchlevel version numbers and the + * release type. A patch is a release type TCL_FINAL_RELEASE with a + * patchLevel > 0. * * Results: * None. @@ -4969,13 +4995,13 @@ Tcl_GetVersion(majorV, minorV, patchLevelV, type) * * Math Functions -- * - * This page contains the procedures that implement all of the - * built-in math functions for expressions. + * This page contains the procedures that implement all of the built-in + * math functions for expressions. * * Results: - * Each procedure returns TCL_OK if it succeeds and pushes an - * Tcl object holding the result. If it fails it returns TCL_ERROR - * and leaves an error message in the interpreter's result. + * Each procedure returns TCL_OK if it succeeds and pushes an Tcl object + * holding the result. If it fails it returns TCL_ERROR and leaves an + * error message in the interpreter's result. * * Side effects: * None. @@ -5105,8 +5131,7 @@ ExprUnaryFunc(clientData, interp, objc, objv) { int code; double d; - double (*func) _ANSI_ARGS_((double)) = - (double (*)_ANSI_ARGS_((double))) clientData; + double (*func)(double) = (double (*)(double)) clientData; if (objc != 2) { MathFuncWrongNumArgs(interp, 2, objc, objv); @@ -5152,8 +5177,8 @@ CheckDoubleResult(interp, dResult) static int ExprBinaryFunc(clientData, interp, objc, objv) ClientData clientData; /* Contains the address of a procedure that - * takes two double arguments and - * returns a double result. */ + * takes two double arguments and returns a + * double result. */ Tcl_Interp *interp; /* The interpreter in which to execute the * function. */ int objc; /* Actual parameter count */ @@ -5161,8 +5186,7 @@ ExprBinaryFunc(clientData, interp, objc, objv) { int code; double d1, d2; - double (*func) _ANSI_ARGS_((double, double)) = - (double (*)_ANSI_ARGS_((double, double))) clientData; + double (*func)(double, double) = (double (*)(double, double)) clientData; if (objc != 3) { MathFuncWrongNumArgs(interp, 3, objc, objv); @@ -5508,7 +5532,7 @@ ExprRandFunc(clientData, interp, objc, objv) if (!(iPtr->flags & RAND_SEED_INITIALIZED)) { iPtr->flags |= RAND_SEED_INITIALIZED; - /* + /* * Take into consideration the thread this interp is running in order * to insure different seeds in different threads (bug #416643) */ @@ -5516,7 +5540,7 @@ ExprRandFunc(clientData, interp, objc, objv) iPtr->randSeed = TclpGetClicks() + ((long)Tcl_GetCurrentThread()<<12); /* - * Make sure 1 <= randSeed <= (2^31) - 2. See below. + * Make sure 1 <= randSeed <= (2^31) - 2. See below. */ iPtr->randSeed &= (unsigned long) 0x7fffffff; @@ -5526,30 +5550,29 @@ ExprRandFunc(clientData, interp, objc, objv) } /* - * Generate the random number using the linear congruential - * generator defined by the following recurrence: + * Generate the random number using the linear congruential generator + * defined by the following recurrence: * seed = ( IA * seed ) mod IM - * where IA is 16807 and IM is (2^31) - 1. The recurrence maps - * a seed in the range [1, IM - 1] to a new seed in that same range. - * The recurrence maps IM to 0, and maps 0 back to 0, so those two - * values must not be allowed as initial values of seed. + * where IA is 16807 and IM is (2^31) - 1. The recurrence maps a seed in + * the range [1, IM - 1] to a new seed in that same range. The recurrence + * maps IM to 0, and maps 0 back to 0, so those two values must not be + * allowed as initial values of seed. * * In order to avoid potential problems with integer overflow, the - * recurrence is implemented in terms of additional constants - * IQ and IR such that + * recurrence is implemented in terms of additional constants IQ and IR + * such that * IM = IA*IQ + IR - * None of the operations in the implementation overflows a 32-bit - * signed integer, and the C type long is guaranteed to be at least - * 32 bits wide. + * None of the operations in the implementation overflows a 32-bit signed + * integer, and the C type long is guaranteed to be at least 32 bits wide. * * For more details on how this algorithm works, refer to the following - * papers: + * papers: * - * S.K. Park & K.W. Miller, "Random number generators: good ones - * are hard to find," Comm ACM 31(10):1192-1201, Oct 1988 + * S.K. Park & K.W. Miller, "Random number generators: good ones are hard + * to find," Comm ACM 31(10):1192-1201, Oct 1988 * - * W.H. Press & S.A. Teukolsky, "Portable random number - * generators," Computers in Physics 6(5):522-524, Sep/Oct 1992. + * W.H. Press & S.A. Teukolsky, "Portable random number generators," + * Computers in Physics 6(5):522-524, Sep/Oct 1992. */ #define RAND_IA 16807 @@ -5596,7 +5619,9 @@ ExprRoundFunc(clientData, interp, objc, objv) Tcl_Obj *resPtr; #endif - /* Check the argument count. */ + /* + * Check the argument count. + */ if (objc != 2) { MathFuncWrongNumArgs(interp, 1, objc, objv); @@ -5604,7 +5629,9 @@ ExprRoundFunc(clientData, interp, objc, objv) } valuePtr = objv[1]; - /* Coerce the argument to a number. Integers are already rounded. */ + /* + * Coerce the argument to a number. Integers are already rounded. + */ #if 0 if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { @@ -5617,9 +5644,9 @@ ExprRoundFunc(clientData, interp, objc, objv) } GET_DOUBLE_VALUE(d, valuePtr, valuePtr->typePtr); - /* - * Round the number to the nearest integer. I'd like to use round(), - * but it's C99 (or BSD), and not yet universal. + /* + * Round the number to the nearest integer. I'd like to use round(), but + * it's C99 (or BSD), and not yet universal. */ d = valuePtr->internalRep.doubleValue; @@ -5634,7 +5661,7 @@ ExprRoundFunc(clientData, interp, objc, objv) resPtr = Tcl_NewWideIntObj(Tcl_DoubleAsWide(i)); } else { resPtr = Tcl_NewLongObj((long) i); - } + } } else { if (f >= 0.5) { i += 1.0; @@ -5734,8 +5761,8 @@ ExprSrandFunc(clientData, interp, objc, objv) } /* - * Reset the seed. Make sure 1 <= randSeed <= 2^31 - 2. - * See comments in ExprRandFunc() for more details. + * Reset the seed. Make sure 1 <= randSeed <= 2^31 - 2. See comments in + * ExprRandFunc() for more details. */ iPtr->flags |= RAND_SEED_INITIALIZED; @@ -5746,9 +5773,9 @@ ExprSrandFunc(clientData, interp, objc, objv) } /* - * To avoid duplicating the random number generation code we simply - * clean up our state and call the real random number function. That - * function will always succeed. + * To avoid duplicating the random number generation code we simply clean + * up our state and call the real random number function. That function + * will always succeed. */ return ExprRandFunc(clientData, interp, 1, objv); @@ -5761,10 +5788,10 @@ ExprSrandFunc(clientData, interp, objc, objv) * * VerifyExprObjType -- * - * This procedure is called by the math functions to verify that - * the object is either an int or double, coercing it if necessary. - * If an error occurs during conversion, an error message is left - * in the interpreter's result unless "interp" is NULL. + * This procedure is called by the math functions to verify that the + * object is either an int or double, coercing it if necessary. If an + * error occurs during conversion, an error message is left in the + * interpreter's result unless "interp" is NULL. * * Results: * TCL_OK if it was int or double, TCL_ERROR otherwise @@ -5817,14 +5844,14 @@ VerifyExprObjType(interp, objPtr) * * MathFuncWrongNumArgs -- * - * Generate an error message when a math function presents the - * wrong number of arguments + * Generate an error message when a math function presents the wrong + * number of arguments. * * Results: * None. * * Side effects: - * An error message is stored in the interpreter result + * An error message is stored in the interpreter result. * *---------------------------------------------------------------------- */ @@ -5839,6 +5866,7 @@ MathFuncWrongNumArgs(interp, expected, found, objv) Tcl_Obj* errorMessage; CONST char* name = Tcl_GetString(objv[0]); CONST char* tail = name + strlen(name); + while (tail > name+1) { --tail; if (*tail == ':' && tail[-1] == ':') { @@ -5857,3 +5885,11 @@ MathFuncWrongNumArgs(interp, expected, found, objv) Tcl_AppendToObj(errorMessage, "\"", -1); Tcl_SetObjResult(interp, errorMessage); } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index fb17fde..33fe242 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdAH.c,v 1.57.2.7 2005/08/29 18:38:45 dgp Exp $ + * RCS: @(#) $Id: tclCmdAH.c,v 1.57.2.8 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -1900,6 +1900,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) int objc; /* Number of arguments. */ Tcl_Obj *CONST objv[]; /* Argument objects. */ { +#ifndef NEW_FORMAT char *format; /* Used to read characters from the format * string. */ int formatLen; /* The length of the format string */ @@ -1932,7 +1933,9 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) #define WIDE_VALUE 5 #define MAX_FLOAT_SIZE 320 +#endif Tcl_Obj *resultPtr; /* Where result is stored finally. */ +#ifndef NEW_FORMAT char staticBuf[MAX_FLOAT_SIZE + 1]; /* A static buffer to copy the format results * into */ @@ -1974,12 +1977,25 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) * So, what happens here is to scan the format string one % group at a * time, making many individual calls to sprintf. */ +#endif if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "formatString ?arg arg ...?"); return TCL_ERROR; } +#ifdef NEW_FORMAT + resultPtr = Tcl_NewObj(); + Tcl_IncrRefCount(resultPtr); + if (TclAppendFormattedObjs(interp, resultPtr, Tcl_GetString(objv[1]), + objc-2, objv+2) != TCL_OK) { + Tcl_DecrRefCount(resultPtr); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, resultPtr); + Tcl_DecrRefCount(resultPtr); + return TCL_OK; +#else format = Tcl_GetStringFromObj(objv[1], &formatLen); endPtr = format + formatLen; resultPtr = Tcl_NewObj(); @@ -2382,6 +2398,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) } Tcl_DecrRefCount(resultPtr); return TCL_ERROR; +#endif } /* diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 27aac85..7fd7c09 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEncoding.c,v 1.29.2.5 2005/08/02 18:15:23 dgp Exp $ + * RCS: @(#) $Id: tclEncoding.c,v 1.29.2.6 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -467,7 +467,7 @@ TclSetLibraryPath(path) *--------------------------------------------------------------------------- */ -void +static void FillEncodingFileMap() { int i, numDirs = 0; @@ -3242,7 +3242,7 @@ unilen(src) *------------------------------------------------------------------------- */ -void +static void InitializeEncodingSearchPath(valuePtr, lengthPtr, encodingPtr) char **valuePtr; int *lengthPtr; diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c index 9c79de0..3e79e5a 100644 --- a/generic/tclIORChan.c +++ b/generic/tclIORChan.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIORChan.c,v 1.1.2.2 2005/08/25 15:46:31 dgp Exp $ + * RCS: @(#) $Id: tclIORChan.c,v 1.1.2.3 2005/09/09 18:48:40 dgp Exp $ */ #include @@ -1949,7 +1949,7 @@ RcNew (interp, cmdpfxObj, mode, id) *---------------------------------------------------------------------- */ -Tcl_Obj* +static Tcl_Obj* RcNewHandle () { /* Count number of generated reflected channels. Used for id diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 0415fed..7041037 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -17,7 +17,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOUtil.c,v 1.113.2.5 2005/08/02 18:15:32 dgp Exp $ + * RCS: @(#) $Id: tclIOUtil.c,v 1.113.2.6 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -1045,7 +1045,8 @@ Tcl_FSUnregister(fsPtr) int Tcl_FSMatchInDirectory(interp, resultPtr, pathPtr, pattern, types) - Tcl_Interp *interp; /* Interpreter to receive error messages. */ + Tcl_Interp *interp; /* Interpreter to receive error + * messages, but may be NULL. */ Tcl_Obj *resultPtr; /* List object to receive results. */ Tcl_Obj *pathPtr; /* Contains path to directory to search. */ CONST char *pattern; /* Pattern to match against. */ diff --git a/generic/tclInt.h b/generic/tclInt.h index 1288198..8c17f8b 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.202.2.37 2005/09/02 17:42:24 dgp Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.202.2.38 2005/09/09 18:48:40 dgp Exp $ */ #ifndef _TCLINT @@ -1727,6 +1727,10 @@ typedef struct List { int refCount; int maxElemCount; /* Total number of element array slots. */ int elemCount; /* Current number of list elements. */ + int canonicalFlag; /* Set if the string representation was + * derived from the list representation. May + * be ignored if there is no string rep at + * all.*/ Tcl_Obj *elements; /* First list element; the struct is grown to * accomodate all elements. */ } List; @@ -1981,6 +1985,9 @@ MODULE_SCOPE char tclEmptyString; *---------------------------------------------------------------- */ +MODULE_SCOPE int TclAppendFormattedObjs(Tcl_Interp *interp, + Tcl_Obj *appendObj, CONST char *format, + int objc, Tcl_Obj *CONST objv[]); MODULE_SCOPE void TclAppendLimitedToObj(Tcl_Obj *objPtr, CONST char *bytes, int length, int limit, CONST char *ellipsis); @@ -2031,6 +2038,7 @@ MODULE_SCOPE void TclFinalizeSynchronization(void); MODULE_SCOPE void TclFinalizeThreadData(void); MODULE_SCOPE double TclFloor(mp_int* a); MODULE_SCOPE void TclFormatNaN(double value, char* buffer); +MODULE_SCOPE int TclFormatObj TCL_VARARGS(Tcl_Interp *, arg1); MODULE_SCOPE int TclFSFileAttrIndex(Tcl_Obj *pathPtr, CONST char *attributeName, int *indexPtr); MODULE_SCOPE Tcl_Obj * TclGetBgErrorHandler(Tcl_Interp *interp); @@ -2088,6 +2096,7 @@ MODULE_SCOPE int TclMergeReturnOptions(Tcl_Interp *interp, int objc, MODULE_SCOPE int TclObjInvokeNamespace(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Namespace *nsPtr, int flags); +MODULE_SCOPE int TclObjPrintf TCL_VARARGS(Tcl_Interp *, arg1); MODULE_SCOPE int TclParseBackslash(CONST char *src, int numBytes, int *readPtr, char *dst); MODULE_SCOPE int TclParseHex(CONST char *src, int numBytes, diff --git a/generic/tclLink.c b/generic/tclLink.c index 9240683..9312907 100644 --- a/generic/tclLink.c +++ b/generic/tclLink.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclLink.c,v 1.8.6.4 2005/08/29 18:38:45 dgp Exp $ + * RCS: @(#) $Id: tclLink.c,v 1.8.6.5 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -32,9 +32,18 @@ typedef struct Link { char *addr; /* Location of C variable. */ int type; /* Type of link (TCL_LINK_INT, etc.). */ union { + char c; + unsigned char uc; int i; - double d; + unsigned int ui; + short s; + unsigned short us; + long l; + unsigned long ul; Tcl_WideInt w; + Tcl_WideUInt uw; + float f; + double d; } lastValue; /* Last known value of C variable; used to * avoid string conversions. */ int flags; /* Miscellaneous one-bit values; see below for @@ -233,6 +242,9 @@ LinkTraceProc(clientData, interp, name1, name2, flags) CONST char *value; char **pp; Tcl_Obj *valueObj; + int valueInt; + Tcl_WideInt valueWide; + double valueDouble; /* * If the variable is being unset, then just re-create it (with a trace) @@ -280,6 +292,38 @@ LinkTraceProc(clientData, interp, name1, name2, flags) case TCL_LINK_WIDE_INT: changed = *(Tcl_WideInt *)(linkPtr->addr) != linkPtr->lastValue.w; break; + case TCL_LINK_WIDE_UINT: + changed = *(Tcl_WideUInt *)(linkPtr->addr) != + linkPtr->lastValue.uw; + break; + case TCL_LINK_CHAR: + changed = *(char *)(linkPtr->addr) != linkPtr->lastValue.c; + break; + case TCL_LINK_UCHAR: + changed = *(unsigned char *)(linkPtr->addr) != + linkPtr->lastValue.uc; + break; + case TCL_LINK_SHORT: + changed = *(short *)(linkPtr->addr) != linkPtr->lastValue.s; + break; + case TCL_LINK_USHORT: + changed = *(unsigned short *)(linkPtr->addr) != + linkPtr->lastValue.us; + break; + case TCL_LINK_UINT: + changed = *(unsigned int *)(linkPtr->addr) != + linkPtr->lastValue.ui; + break; + case TCL_LINK_LONG: + changed = *(long *)(linkPtr->addr) != linkPtr->lastValue.l; + break; + case TCL_LINK_ULONG: + changed = *(unsigned long *)(linkPtr->addr) != + linkPtr->lastValue.ul; + break; + case TCL_LINK_FLOAT: + changed = *(float *)(linkPtr->addr) != linkPtr->lastValue.f; + break; case TCL_LINK_STRING: changed = 1; break; @@ -363,6 +407,107 @@ LinkTraceProc(clientData, interp, name1, name2, flags) *(int *)(linkPtr->addr) = linkPtr->lastValue.i; break; + case TCL_LINK_CHAR: + if (Tcl_GetIntFromObj(interp, valueObj, &valueInt) != TCL_OK + || valueInt < SCHAR_MIN || valueInt > SCHAR_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have char value"; + } + linkPtr->lastValue.c = (char)valueInt; + *(char *)(linkPtr->addr) = linkPtr->lastValue.c; + break; + + case TCL_LINK_UCHAR: + if (Tcl_GetIntFromObj(interp, valueObj, &valueInt) != TCL_OK + || valueInt < 0 || valueInt > UCHAR_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have unsigned char value"; + } + linkPtr->lastValue.uc = (unsigned char) valueInt; + *(unsigned char *)(linkPtr->addr) = linkPtr->lastValue.uc; + break; + + case TCL_LINK_SHORT: + if (Tcl_GetIntFromObj(interp, valueObj, &valueInt) != TCL_OK + || valueInt < SHRT_MIN || valueInt > SHRT_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have short value"; + } + linkPtr->lastValue.s = (short)valueInt; + *(short *)(linkPtr->addr) = linkPtr->lastValue.s; + break; + + case TCL_LINK_USHORT: + if (Tcl_GetIntFromObj(interp, valueObj, &valueInt) != TCL_OK + || valueInt < 0 || valueInt > USHRT_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have unsigned short value"; + } + linkPtr->lastValue.us = (unsigned short)valueInt; + *(unsigned short *)(linkPtr->addr) = linkPtr->lastValue.us; + break; + + case TCL_LINK_UINT: + if (Tcl_GetWideIntFromObj(interp, valueObj, &valueWide) != TCL_OK + || valueWide < 0 || valueWide > UINT_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have unsigned int value"; + } + linkPtr->lastValue.ui = (unsigned int)valueWide; + *(unsigned int *)(linkPtr->addr) = linkPtr->lastValue.ui; + break; + + case TCL_LINK_LONG: + if (Tcl_GetWideIntFromObj(interp, valueObj, &valueWide) != TCL_OK + || valueWide < LONG_MIN || valueWide > LONG_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have long value"; + } + linkPtr->lastValue.l = (long)valueWide; + *(long *)(linkPtr->addr) = linkPtr->lastValue.l; + break; + + case TCL_LINK_ULONG: + if (Tcl_GetWideIntFromObj(interp, valueObj, &valueWide) != TCL_OK + || valueWide < 0 || valueWide > ULONG_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have unsigned long value"; + } + linkPtr->lastValue.ul = (unsigned long)valueWide; + *(unsigned long *)(linkPtr->addr) = linkPtr->lastValue.ul; + break; + + case TCL_LINK_WIDE_UINT: + /* + * FIXME: represent as a bignum. + */ + if (Tcl_GetWideIntFromObj(interp, valueObj, &valueWide) != TCL_OK) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have unsigned wide int value"; + } + linkPtr->lastValue.uw = (Tcl_WideUInt)valueWide; + *(Tcl_WideUInt *)(linkPtr->addr) = linkPtr->lastValue.uw; + break; + + case TCL_LINK_FLOAT: + if (Tcl_GetDoubleFromObj(interp, valueObj, &valueDouble) != TCL_OK + || valueDouble < FLT_MIN || valueDouble > FLT_MAX) { + Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr), + TCL_GLOBAL_ONLY); + return "variable must have float value"; + } + linkPtr->lastValue.f = (float)valueDouble; + *(float *)(linkPtr->addr) = linkPtr->lastValue.f; + break; + case TCL_LINK_STRING: value = Tcl_GetStringFromObj(valueObj, &valueLength); valueLength++; @@ -417,6 +562,36 @@ ObjValue(linkPtr) case TCL_LINK_BOOLEAN: linkPtr->lastValue.i = *(int *)(linkPtr->addr); return Tcl_NewBooleanObj(linkPtr->lastValue.i != 0); + case TCL_LINK_CHAR: + linkPtr->lastValue.c = *(char *)(linkPtr->addr); + return Tcl_NewIntObj(linkPtr->lastValue.c); + case TCL_LINK_UCHAR: + linkPtr->lastValue.uc = *(unsigned char *)(linkPtr->addr); + return Tcl_NewIntObj(linkPtr->lastValue.uc); + case TCL_LINK_SHORT: + linkPtr->lastValue.s = *(short *)(linkPtr->addr); + return Tcl_NewIntObj(linkPtr->lastValue.s); + case TCL_LINK_USHORT: + linkPtr->lastValue.us = *(unsigned short *)(linkPtr->addr); + return Tcl_NewIntObj(linkPtr->lastValue.us); + case TCL_LINK_UINT: + linkPtr->lastValue.ui = *(unsigned int *)(linkPtr->addr); + return Tcl_NewWideIntObj(linkPtr->lastValue.ui); + case TCL_LINK_LONG: + linkPtr->lastValue.l = *(long *)(linkPtr->addr); + return Tcl_NewWideIntObj(linkPtr->lastValue.l); + case TCL_LINK_ULONG: + linkPtr->lastValue.ul = *(unsigned long *)(linkPtr->addr); + return Tcl_NewWideIntObj(linkPtr->lastValue.ul); + case TCL_LINK_FLOAT: + linkPtr->lastValue.f = *(float *)(linkPtr->addr); + return Tcl_NewDoubleObj(linkPtr->lastValue.f); + case TCL_LINK_WIDE_UINT: + linkPtr->lastValue.uw = *(Tcl_WideUInt *)(linkPtr->addr); + /* + * FIXME: represent as a bignum. + */ + return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.uw); case TCL_LINK_STRING: p = *(char **)(linkPtr->addr); if (p == NULL) { diff --git a/generic/tclListObj.c b/generic/tclListObj.c index a9cbe65..b5d759a 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclListObj.c,v 1.20.2.3 2005/08/29 18:38:45 dgp Exp $ + * RCS: @(#) $Id: tclListObj.c,v 1.20.2.4 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -19,14 +19,11 @@ * Prototypes for functions defined later in this file: */ -static List* NewListIntRep _ANSI_ARGS_((int objc, - Tcl_Obj *CONST objv[])); -static void DupListInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr, - Tcl_Obj *copyPtr)); -static void FreeListInternalRep _ANSI_ARGS_((Tcl_Obj *listPtr)); -static int SetListFromAny _ANSI_ARGS_((Tcl_Interp *interp, - Tcl_Obj *objPtr)); -static void UpdateStringOfList _ANSI_ARGS_((Tcl_Obj *listPtr)); +static List * NewListIntRep(int objc, Tcl_Obj *CONST objv[]); +static void DupListInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr); +static void FreeListInternalRep(Tcl_Obj *listPtr); +static int SetListFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); +static void UpdateStringOfList(Tcl_Obj *listPtr); /* * The structure below defines the list Tcl object type by means of functions @@ -42,11 +39,11 @@ static void UpdateStringOfList _ANSI_ARGS_((Tcl_Obj *listPtr)); */ Tcl_ObjType tclListType = { - "list", /* name */ - FreeListInternalRep, /* freeIntRepProc */ - DupListInternalRep, /* dupIntRepProc */ - UpdateStringOfList, /* updateStringProc */ - NULL /* setFromAnyProc */ + "list", /* name */ + FreeListInternalRep, /* freeIntRepProc */ + DupListInternalRep, /* dupIntRepProc */ + UpdateStringOfList, /* updateStringProc */ + NULL /* setFromAnyProc */ }; @@ -74,7 +71,7 @@ Tcl_ObjType tclListType = { *---------------------------------------------------------------------- */ -List* +static List* NewListIntRep(objc, objv) int objc; Tcl_Obj *CONST objv[]; @@ -89,7 +86,7 @@ NewListIntRep(objc, objv) /* * First check to see if we'd overflow and try to allocate an object - * larger than our memory allocator allows. Note that this is actually a + * larger than our memory allocator allows. Note that this is actually a * fairly small value when you're on a serious 64-bit machine, but that * requires API changes to fix. */ @@ -104,6 +101,7 @@ NewListIntRep(objc, objv) return NULL; } + listRepPtr->canonicalFlag = 0; listRepPtr->refCount = 0; listRepPtr->maxElemCount = objc; @@ -771,7 +769,7 @@ Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) elemPtrs = &listRepPtr->elements; numElems = listRepPtr->elemCount; - if (first < 0) { + if (first < 0) { first = 0; } if (first >= numElems) { @@ -954,8 +952,8 @@ Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) * * Tcl_LsetFlat and related functions maintain a linked list of Tcl_Obj's * whose string representations must be spoilt by threading via 'ptr2' of - * the two-pointer internal representation. On entry to Tcl_LsetList, - * the values of 'ptr2' are immaterial; on exit, the 'ptr2' field of any + * the two-pointer internal representation. On entry to Tcl_LsetList, the + * values of 'ptr2' are immaterial; on exit, the 'ptr2' field of any * Tcl_Obj that has been modified is set to NULL. * *---------------------------------------------------------------------- @@ -993,7 +991,7 @@ TclLsetList(interp, listPtr, indexArgPtr, valuePtr) &indices) != TCL_OK) { /* * indexArgPtr designates something that is neither an index nor a - * well formed list. Report the error via TclLsetFlat. + * well formed list. Report the error via TclLsetFlat. */ return TclLsetFlat(interp, listPtr, 1, &indexArgPtr, valuePtr); @@ -1041,7 +1039,7 @@ TclLsetList(interp, listPtr, indexArgPtr, valuePtr) * * TclLsetFlat -- * - * Core of the 'lset' command when objc>=5. Objv[2], ... , objv[objc-2] + * Core of the 'lset' command when objc>=5. Objv[2], ... , objv[objc-2] * contain scalar indices. * * Results: @@ -1064,18 +1062,18 @@ TclLsetList(interp, listPtr, indexArgPtr, valuePtr) * * If no error occurs, the reference count of the original object is * incremented if the object has not been duplicated, and nothing is done - * to a reference count of the duplicate. Now the reference count of an + * to a reference count of the duplicate. Now the reference count of an * unduplicated object is 2 (the returned pointer, plus the one stored in - * the variable). The reference count of a duplicate object is 1, + * the variable). The reference count of a duplicate object is 1, * reflecting that the returned pointer is the only active reference. * The caller is expected to store the returned value back in the - * variable and decrement its reference count. (INST_STORE_* does - * exactly this.) + * variable and decrement its reference count. (INST_STORE_* does exactly + * this.) * * Tcl_LsetList and related functions maintain a linked list of Tcl_Obj's * whose string representations must be spoilt by threading via 'ptr2' of - * the two-pointer internal representation. On entry to Tcl_LsetList, - * the values of 'ptr2' are immaterial; on exit, the 'ptr2' field of any + * the two-pointer internal representation. On entry to Tcl_LsetList, the + * values of 'ptr2' are immaterial; on exit, the 'ptr2' field of any * Tcl_Obj that has been modified is set to NULL. * *---------------------------------------------------------------------- @@ -1292,7 +1290,9 @@ TclListObjSetElement(interp, listPtr, index, valuePtr) int elemCount; /* Number of elements in the list */ int i; - /* Ensure that the listPtr parameter designates an unshared list */ + /* + * Ensure that the listPtr parameter designates an unshared list. + */ if (Tcl_IsShared(listPtr)) { Tcl_Panic("Tcl_ListObjSetElement called with shared object"); @@ -1316,7 +1316,9 @@ TclListObjSetElement(interp, listPtr, index, valuePtr) elemCount = listRepPtr->elemCount; elemPtrs = &listRepPtr->elements; - /* Ensure that the index is in bounds. */ + /* + * Ensure that the index is in bounds. + */ if (index<0 || index>=elemCount) { if (interp != NULL) { @@ -1335,6 +1337,7 @@ TclListObjSetElement(interp, listPtr, index, valuePtr) Tcl_Obj **oldElemPtrs = elemPtrs; listRepPtr = NewListIntRep(listRepPtr->maxElemCount, NULL); + listRepPtr->canonicalFlag = oldListRepPtr->canonicalFlag; elemPtrs = &listRepPtr->elements; for (i=0; i < elemCount; i++) { elemPtrs[i] = oldElemPtrs[i]; @@ -1346,15 +1349,21 @@ TclListObjSetElement(interp, listPtr, index, valuePtr) oldListRepPtr->refCount--; } - /* Add a reference to the new list element */ + /* + * Add a reference to the new list element. + */ Tcl_IncrRefCount(valuePtr); - /* Remove a reference from the old list element */ + /* + * Remove a reference from the old list element. + */ Tcl_DecrRefCount(elemPtrs[index]); - /* Stash the new object in the list */ + /* + * Stash the new object in the list. + */ elemPtrs[index] = valuePtr; @@ -1473,11 +1482,10 @@ SetListFromAny(interp, objPtr) /* * Parse the string into separate string objects, and create a List - * structure that points to the element string objects. We use a - * modified version of Tcl_SplitList's implementation to avoid one - * malloc and a string copy for each list element. First, estimate the - * number of elements by counting the number of space characters in the - * list. + * structure that points to the element string objects. We use a modified + * version of Tcl_SplitList's implementation to avoid one malloc and a + * string copy for each list element. First, estimate the number of + * elements by counting the number of space characters in the list. */ limit = (string + length); @@ -1489,14 +1497,14 @@ SetListFromAny(interp, objPtr) } /* - * Allocate a new List structure with enough room for "estCount" - * elements. Each element is a pointer to a Tcl_Obj with the appropriate - * string rep. The initial "estCount" elements are set using the - * corresponding "argv" strings. + * Allocate a new List structure with enough room for "estCount" elements. + * Each element is a pointer to a Tcl_Obj with the appropriate string rep. + * The initial "estCount" elements are set using the corresponding "argv" + * strings. */ listRepPtr = NewListIntRep(estCount, NULL); - if(!listRepPtr) { + if (!listRepPtr) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "Not enough memory to allocate the list internal rep", -1)); return TCL_ERROR; @@ -1530,20 +1538,20 @@ SetListFromAny(interp, objPtr) s = ckalloc((unsigned) elemSize + 1); if (hasBrace) { - memcpy((VOID *) s, (VOID *) elemStart, (size_t) elemSize); + memcpy((VOID *) s, (VOID *) elemStart, (size_t) elemSize); s[elemSize] = 0; } else { elemSize = TclCopyAndCollapse(elemSize, elemStart, s); } TclNewObj(elemPtr); - elemPtr->bytes = s; + elemPtr->bytes = s; elemPtr->length = elemSize; elemPtrs[i] = elemPtr; - Tcl_IncrRefCount(elemPtr); /* since list now holds ref to it */ + Tcl_IncrRefCount(elemPtr); /* since list now holds ref to it */ } - listRepPtr->elemCount = i; + listRepPtr->elemCount = i; /* * Free the old internalRep before setting the new one. We do this as late @@ -1613,9 +1621,11 @@ UpdateStringOfList(listPtr) elem = Tcl_GetStringFromObj(elemPtrs[i], &length); listPtr->length += Tcl_ScanCountedElement(elem, length, &flagPtr[i]) + 1; + /* * Check for continued sanity. [Bug 1267380] */ + if (listPtr->length < 1) { Tcl_Panic("string representation size exceeds sane bounds"); } @@ -1644,6 +1654,14 @@ UpdateStringOfList(listPtr) *dst = 0; } listPtr->length = dst - listPtr->bytes; + + /* + * Mark the list as being canonical; although it has a string rep, it is + * one we derived through proper "canonical" quoting and so it's known to + * be free from nasties relating to [concat] and [eval]. + */ + + listRepPtr->canonicalFlag = 1; } /* diff --git a/generic/tclObj.c b/generic/tclObj.c index c65a44b..e238b34 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclObj.c,v 1.72.2.33 2005/09/01 16:27:51 dgp Exp $ + * RCS: @(#) $Id: tclObj.c,v 1.72.2.34 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -133,7 +133,7 @@ static PendingObjData pendingObjData; #define ObjInitDeletionContext(contextPtr) \ PendingObjData *CONST contextPtr = &pendingObjData #else -Tcl_ThreadDataKey pendingObjDataKey; +static Tcl_ThreadDataKey pendingObjDataKey; #define ObjInitDeletionContext(contextPtr) \ PendingObjData *CONST contextPtr = (PendingObjData *) \ Tcl_GetThreadData(&pendingObjDataKey, sizeof(PendingObjData)) diff --git a/generic/tclResult.c b/generic/tclResult.c index 0b038d9..3385cf9 100644 --- a/generic/tclResult.c +++ b/generic/tclResult.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclResult.c,v 1.23.2.3 2005/08/02 18:16:07 dgp Exp $ + * RCS: @(#) $Id: tclResult.c,v 1.23.2.4 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -1151,7 +1151,7 @@ GetKeys() *---------------------------------------------------------------------- */ -void +static void ReleaseKeys(clientData) ClientData clientData; { diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index f5f1e77..a7654c2 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -33,7 +33,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStringObj.c,v 1.35.2.3 2005/08/16 04:26:40 dgp Exp $ */ + * RCS: @(#) $Id: tclStringObj.c,v 1.35.2.4 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -52,6 +52,10 @@ static void AppendUtfToUnicodeRep _ANSI_ARGS_((Tcl_Obj *objPtr, static void AppendUtfToUtfRep _ANSI_ARGS_((Tcl_Obj *objPtr, CONST char *bytes, int numBytes)); static void FillUnicodeRep _ANSI_ARGS_((Tcl_Obj *objPtr)); +static int FormatObjVA _ANSI_ARGS_((Tcl_Interp *interp, + va_list argList)); +static int ObjPrintfVA _ANSI_ARGS_((Tcl_Interp *interp, + va_list argList)); static void FreeStringInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr)); static void DupStringInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr, Tcl_Obj *copyPtr)); @@ -1671,6 +1675,729 @@ Tcl_AppendStringsToObj TCL_VARARGS_DEF(Tcl_Obj *,arg1) } /* + *---------------------------------------------------------------------- + * + * TclAppendFormattedObjs -- + * + * This function appends a list of Tcl_Obj's to a Tcl_Obj according + * to the formatting instructions embedded in the format string. The + * formatting instructions are inspired by sprintf(). Returns TCL_OK + * when successful. If there's an error in the arguments, TCL_ERROR is + * returned, and an error message is written to the interp, if non-NULL. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclAppendFormattedObjs(interp, baseObj, format, objc, objv) + Tcl_Interp *interp; + Tcl_Obj *baseObj; + CONST char *format; + int objc; + Tcl_Obj *CONST objv[]; +{ + CONST char *span = format; + int numBytes = 0; + int objIndex = 0; + int gotXpg = 0, gotSequential = 0; + Tcl_Obj *appendObj = Tcl_NewObj(); + CONST char *msg; + CONST char *mixedXPG = "cannot mix \"%\" and \"%n$\" conversion specifiers"; + CONST char *badIndex[2] = { + "not enough arguments for all format specifiers", + "\"%n$\" argument index out of range" + }; + + if (Tcl_IsShared(baseObj)) { + Tcl_Panic("TclAppendFormattedObjs called with shared object"); + } + + Tcl_IncrRefCount(appendObj); + /* format string is NUL-terminated */ + while (*format != '\0') { + char *end; + int gotMinus, gotHash, gotZero, gotSpace, gotPlus, sawFlag; + int width, gotPrecision, precision, useShort, useWide; + int newXpg, numChars, allocSegment = 0; + Tcl_Obj *segment; + Tcl_UniChar ch; + int step = Tcl_UtfToUniChar(format, &ch); + + format += step; + if (ch != '%') { + numBytes += step; + continue; + } + if (numBytes) { + Tcl_AppendToObj(appendObj, span, numBytes); + numBytes = 0; + } + + /* Saw a % : process the format specifier */ + /* 0. %% : Escape format handling */ + + step = Tcl_UtfToUniChar(format, &ch); + if (ch == '%') { + span = format; + numBytes = step; + format += step; + continue; + } + + /* 1. XPG3 position specifier */ + + newXpg = 0; + if (isdigit(UCHAR(ch))) { + int position = strtoul(format, &end, 10); + if (*end == '$') { + newXpg = 1; + objIndex = position - 1; + format = end + 1; + step = Tcl_UtfToUniChar(format, &ch); + } + } + if (newXpg) { + if (gotSequential) { + msg = mixedXPG; + goto errorMsg; + } + gotXpg = 1; + } else { + if (gotXpg) { + msg = mixedXPG; + goto errorMsg; + } + gotSequential = 1; + } + if ((objIndex < 0) || (objIndex >= objc)) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + + /* 2. Set of flags */ + + gotMinus = gotHash = gotZero = gotSpace = gotPlus = 0; + sawFlag = 1; + do { + switch (ch) { + case '-': + gotMinus = 1; + break; + case '#': + gotHash = 1; + break; + case '0': + gotZero = 1; + break; + case ' ': + gotSpace = 1; + break; + case '+': + gotPlus = 1; + break; + default: + sawFlag = 0; + } + if (sawFlag) { + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } + } while (sawFlag); + + /* 3. Minimum field width */ + + width = 0; + if (isdigit(UCHAR(ch))) { + width = strtoul(format, &end, 10); + format = end; + step = Tcl_UtfToUniChar(format, &ch); + } else if (ch == '*') { + if (objIndex >= objc - 1) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + if (Tcl_GetIntFromObj(interp, objv[objIndex], &width) != TCL_OK) { + goto error; + } + if (width < 0) { + width = -width; + gotMinus = 1; + } + objIndex++; + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } + + /* 4. Precision */ + + gotPrecision = precision = 0; + if (ch == '.') { + gotPrecision = 1; + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } + if (isdigit(UCHAR(ch))) { + precision = strtoul(format, &end, 10); + format = end; + step = Tcl_UtfToUniChar(format, &ch); + } else if (ch == '*') { + if (objIndex >= objc - 1) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + if (Tcl_GetIntFromObj(interp, objv[objIndex], &precision) + != TCL_OK) { + goto error; + } + /* TODO: Check this truncation logic */ + if (precision < 0) { + precision = 0; + } + objIndex++; + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } + + /* 5. Length modifier */ + + useShort = useWide = 0; + if (ch == 'h') { + useShort = 1; + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } else if (ch == 'l') { +#ifndef TCL_WIDE_INT_IS_LONG + useWide = 1; +#endif + format += step; + step = Tcl_UtfToUniChar(format, &ch); + } + + format += step; + span = format; + + /* 6. Conversion character */ + segment = objv[objIndex]; + if (ch == 'i') { + ch = 'd'; + } + switch (ch) { + case '\0': + msg = "format string ended in middle of field specifier"; + goto errorMsg; + case 's': { + numChars = Tcl_GetCharLength(segment); + if (gotPrecision && (precision < numChars)) { + segment = Tcl_GetRange(segment, 0, precision - 1); + Tcl_IncrRefCount(segment); + allocSegment = 1; + } + break; + } + case 'c': { + char buf[TCL_UTF_MAX]; + int code, length; + if (Tcl_GetIntFromObj(interp, segment, &code) != TCL_OK) { + goto error; + } + length = Tcl_UniCharToUtf(code, buf); + segment = Tcl_NewStringObj(buf, length); + Tcl_IncrRefCount(segment); + allocSegment = 1; + break; + } + + case 'u': + case 'd': + case 'o': + case 'x': + case 'X': { + short int s; + long l; + Tcl_WideInt w; + int isNegative = 0; + + if (Tcl_GetLongFromObj(NULL, segment, &l) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, segment, &w) != TCL_OK) { + goto error; + } + l = Tcl_WideAsLong(w); + } else if (useWide) { + w = Tcl_LongAsWide(l); + } + + if (useShort) { + s = (short int) l; + isNegative = (s < (short int)0); + } else if (useWide) { + isNegative = (w < (Tcl_WideInt)0); + } else { + isNegative = (l < (long)0); + } + + segment = Tcl_NewObj(); + allocSegment = 1; + Tcl_IncrRefCount(segment); + + if (isNegative || gotPlus) { + if (ch == 'd') { + if (isNegative) { + Tcl_AppendToObj(segment, "-", 1); + } else { + Tcl_AppendToObj(segment, "+", 1); + } + } + } + + if (gotHash) { + switch (ch) { + case 'o': + Tcl_AppendToObj(segment, "0", 1); + precision--; + break; + case 'x': + case 'X': + Tcl_AppendToObj(segment, "0x", 2); + break; + } + } + + switch (ch) { + case 'd': { + int length; + Tcl_Obj *pure; + CONST char *bytes; + + if (isNegative) { + if (useShort) { + pure = Tcl_NewIntObj((int)(-s)); + } else if (useWide) { + pure = Tcl_NewWideIntObj(-w); + } else { + pure = Tcl_NewLongObj(-l); + } + } else { + if (useShort) { + pure = Tcl_NewIntObj((int)(s)); + } else if (useWide) { + pure = Tcl_NewWideIntObj(w); + } else { + pure = Tcl_NewLongObj(l); + } + } + Tcl_IncrRefCount(pure); + bytes = Tcl_GetStringFromObj(pure, &length); + /* Handle things like -INT_MIN == INT_MIN */ + if (*bytes == '-') { + length--; bytes++; + } + /* Canonical decimal string reps for integers are composed + * entirely of one-byte encoded characters, so "length" is + * the number of chars */ + if (gotPrecision) { + while (length < precision) { + Tcl_AppendToObj(segment, "0", 1); + length++; + } + gotZero = 0; + } + if (gotZero) { + length += Tcl_GetCharLength(segment); + while (length < width) { + Tcl_AppendToObj(segment, "0", 1); + length++; + } + } + Tcl_AppendToObj(segment, bytes, -1); + Tcl_DecrRefCount(pure); + break; + } + + case 'u': + case 'o': + case 'x': + case 'X': { + Tcl_WideUInt bits; + int length, numDigits = 0, base = 16; + Tcl_Obj *pure; + char *bytes; + + if (ch == 'u') { + base = 10; + } + if (ch == 'o') { + base = 8; + } + if (useShort) { + unsigned short int us = (unsigned short int) s; + bits = (Tcl_WideUInt) us; + while (us) { + numDigits++; + us /= base; + } + } else if (useWide) { + Tcl_WideUInt uw = (Tcl_WideUInt) w; + bits = uw; + while (uw) { + numDigits++; + uw /= base; + } + } else { + unsigned long int ul = (unsigned long int) l; + bits = (Tcl_WideUInt) ul; + while (ul) { + numDigits++; + ul /= base; + } + } + /* Need to be sure zero becomes "0", not "" */ + if ((numDigits == 0) && !((ch == 'o') && gotHash)) { + numDigits = 1; + } + pure = Tcl_NewObj(); + Tcl_SetObjLength(pure, numDigits); + bytes = Tcl_GetString(pure); + length = numDigits; + while (numDigits--) { + int digitOffset = (int) (bits % base); + if (digitOffset > 9) { + bytes[numDigits] = 'a' + digitOffset - 10; + } else { + bytes[numDigits] = '0' + digitOffset; + } + bits /= base; + } + if (gotPrecision) { + while (length < precision) { + Tcl_AppendToObj(segment, "0", 1); + length++; + } + gotZero = 0; + } + if (gotZero) { + length += Tcl_GetCharLength(segment); + while (length < width) { + Tcl_AppendToObj(segment, "0", 1); + length++; + } + } + Tcl_AppendObjToObj(segment, pure); + Tcl_DecrRefCount(pure); + break; + } + + } + break; + } + + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': { +#define MAX_FLOAT_SIZE 320 + char spec[2*TCL_INTEGER_SPACE + 9], *p = spec; + double d; + int length = MAX_FLOAT_SIZE; + char *bytes; + + if (Tcl_GetDoubleFromObj(interp, segment, &d) != TCL_OK) { + goto error; + } + *p++ = '%'; + if (gotMinus) { + *p++ = '-'; + } + if (gotHash) { + *p++ = '#'; + } + if (gotZero) { + *p++ = '0'; + } + if (gotSpace) { + *p++ = ' '; + } + if (gotPlus) { + *p++ = '+'; + } + if (width) { + p += sprintf(p, "%d", width); + } + if (gotPrecision) { + *p++ = '.'; + p += sprintf(p, "%d", precision); + length += precision; + } + /* Don't pass length modifiers ! */ + *p++ = (char) ch; + *p = '\0'; + + segment = Tcl_NewObj(); + allocSegment = 1; + Tcl_SetObjLength(segment, length); + bytes = Tcl_GetString(segment); + Tcl_SetObjLength(segment, sprintf(bytes, spec, d)); + break; + } + default: { + char buf[40]; + sprintf(buf, "bad field specifier \"%c\"", ch); + msg = buf; + goto errorMsg; + } + } + + switch (ch) { + case 'E': + case 'G': + case 'X': { + Tcl_SetObjLength(segment, Tcl_UtfToUpper(Tcl_GetString(segment))); + } + } + + numChars = Tcl_GetCharLength(segment); + if (!gotMinus) { + while (numChars < width) { + Tcl_AppendToObj(appendObj, (gotZero ? "0" : " "), 1); + numChars++; + } + } + Tcl_AppendObjToObj(appendObj, segment); + if (allocSegment) { + Tcl_DecrRefCount(segment); + } + while (numChars < width) { + Tcl_AppendToObj(appendObj, (gotZero ? "0" : " "), 1); + numChars++; + } + + objIndex += gotSequential; + } + if (numBytes) { + Tcl_AppendToObj(appendObj, span, numBytes); + numBytes = 0; + } + + Tcl_AppendObjToObj(baseObj, appendObj); + Tcl_DecrRefCount(appendObj); + return TCL_OK; + + errorMsg: + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1)); + } + error: + Tcl_DecrRefCount(appendObj); + return TCL_ERROR; +} + +/* + *--------------------------------------------------------------------------- + * + * FormatObjVA -- + * + * Populate the Unicode internal rep with the Unicode form of its string + * rep. The object must alread have a "String" internal rep. + * + * Results: + * None. + * + * Side effects: + * Reallocates the String internal rep. + * + *--------------------------------------------------------------------------- + */ + +static int +FormatObjVA(interp, argList) + Tcl_Interp *interp; + va_list argList; +{ + int code, objc; + Tcl_Obj **objv, *element, *list = Tcl_NewObj(); + CONST char *format; + Tcl_Obj *objPtr = va_arg(argList, Tcl_Obj *); + + if (objPtr == NULL) { + Tcl_Panic("TclFormatObj: no Tcl_Obj to append to"); + } + + format = va_arg(argList, CONST char *); + if (format == NULL) { + Tcl_Panic("TclFormatObj: no format string argument"); + } + + Tcl_IncrRefCount(list); + element = va_arg(argList, Tcl_Obj *); + while (element != NULL) { + Tcl_ListObjAppendElement(NULL, list, element); + element = va_arg(argList, Tcl_Obj *); + } + Tcl_ListObjGetElements(NULL, list, &objc, &objv); + code = TclAppendFormattedObjs(interp, objPtr, format, objc, objv); + Tcl_DecrRefCount(list); + return code; +} + +/* + *--------------------------------------------------------------------------- + * + * TclFormatObj -- + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +int +TclFormatObj TCL_VARARGS_DEF(Tcl_Interp *,arg1) +{ + va_list argList; + int result; + Tcl_Interp *interp = TCL_VARARGS_START(Tcl_Interp *,arg1,argList); + result = FormatObjVA(interp, argList); + va_end(argList); + return result; +} + +/* + *--------------------------------------------------------------------------- + * + * ObjPrintfVA -- + * + * Results: + * + * Side effects: + * + *--------------------------------------------------------------------------- + */ + +static int +ObjPrintfVA(interp, argList) + Tcl_Interp *interp; + va_list argList; +{ + int code, objc; + Tcl_Obj **objv, *element, *list = Tcl_NewObj(); + CONST char *format, *p; + Tcl_Obj *objPtr = va_arg(argList, Tcl_Obj *); + + if (objPtr == NULL) { + Tcl_Panic("TclObjPrintf: no Tcl_Obj to append to"); + } + + p = format = va_arg(argList, CONST char *); + if (format == NULL) { + Tcl_Panic("TclObjPrintf: no format string argument"); + } + + Tcl_IncrRefCount(list); + while (*p != '\0') { + int size = 0; + int seekingConversion = 1; + if (*p++ != '%') { + continue; + } + if (*p == '%') { + p++; + continue; + } + do { + switch (*p) { + + case '\0': + seekingConversion = 0; + break; + case 's': + Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj( + va_arg(argList, char *), -1)); + seekingConversion = 0; + break; + case 'c': + case 'i': + case 'u': + case 'd': + case 'o': + case 'x': + case 'X': + seekingConversion = 0; + switch (size) { + case -1: + Tcl_ListObjAppendElement(NULL, list, Tcl_NewLongObj( + (long int)va_arg(argList, short int))); + break; + case 0: + Tcl_ListObjAppendElement(NULL, list, Tcl_NewLongObj( + (long int)va_arg(argList, int))); + break; + case 1: + Tcl_ListObjAppendElement(NULL, list, Tcl_NewLongObj( + va_arg(argList, long int))); + break; + } + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + Tcl_ListObjAppendElement(NULL, list, Tcl_NewDoubleObj( + va_arg(argList, double))); + seekingConversion = 0; + break; + case 'l': + size = 1; + p++; + break; + case 'h': + size = -1; + default: + p++; + } + } while (seekingConversion); + } + Tcl_ListObjGetElements(NULL, list, &objc, &objv); + code = TclAppendFormattedObjs(interp, objPtr, format, objc, objv); + Tcl_DecrRefCount(list); + return code; +} + +/* + *--------------------------------------------------------------------------- + * + * TclObjPrintf -- + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +int +TclObjPrintf TCL_VARARGS_DEF(Tcl_Interp *,arg1) +{ + va_list argList; + int result; + Tcl_Interp *interp = TCL_VARARGS_START(Tcl_Interp *,arg1,argList); + result = ObjPrintfVA(interp, argList); + va_end(argList); + return result; +} + +/* *--------------------------------------------------------------------------- * * FillUnicodeRep -- diff --git a/generic/tclTest.c b/generic/tclTest.c index ff8d896..1e39cfc 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclTest.c,v 1.86.2.6 2005/08/25 15:46:31 dgp Exp $ + * RCS: @(#) $Id: tclTest.c,v 1.86.2.7 2005/09/09 18:48:40 dgp Exp $ */ #define TCL_TEST @@ -2703,6 +2703,15 @@ TestlinkCmd(dummy, interp, argc, argv) static double realVar = 1.23; static Tcl_WideInt wideVar = Tcl_LongAsWide(79); static char *stringVar = NULL; + static char charVar = '@'; + static unsigned char ucharVar = 130; + static short shortVar = 3000; + static unsigned short ushortVar = 60000; + static unsigned int uintVar = 0xbeeffeed; + static long longVar = 123456789L; + static unsigned long ulongVar = 3456789012UL; + static float floatVar = 4.5; + static Tcl_WideUInt uwideVar = (Tcl_WideUInt) Tcl_LongAsWide(123); static int created = 0; char buffer[2*TCL_DOUBLE_SPACE]; int writable, flag; @@ -2710,14 +2719,17 @@ TestlinkCmd(dummy, interp, argc, argv) if (argc < 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " option ?arg arg arg arg arg?\"", (char *) NULL); + " option ?arg arg arg arg arg arg arg arg arg arg arg arg", + " arg arg?\"", (char *) NULL); return TCL_ERROR; } if (strcmp(argv[1], "create") == 0) { - if (argc != 7) { + if (argc != 16) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ", argv[1], - " intRO realRO boolRO stringRO wideRO\"", (char *) NULL); + " intRO realRO boolRO stringRO wideRO charRO ucharRO shortRO", + " ushortRO uintRO longRO ulongRO floatRO uwideRO\"", + (char *) NULL); return TCL_ERROR; } if (created) { @@ -2726,6 +2738,15 @@ TestlinkCmd(dummy, interp, argc, argv) Tcl_UnlinkVar(interp, "bool"); Tcl_UnlinkVar(interp, "string"); Tcl_UnlinkVar(interp, "wide"); + Tcl_UnlinkVar(interp, "char"); + Tcl_UnlinkVar(interp, "uchar"); + Tcl_UnlinkVar(interp, "short"); + Tcl_UnlinkVar(interp, "ushort"); + Tcl_UnlinkVar(interp, "uint"); + Tcl_UnlinkVar(interp, "long"); + Tcl_UnlinkVar(interp, "ulong"); + Tcl_UnlinkVar(interp, "float"); + Tcl_UnlinkVar(interp, "uwide"); } created = 1; if (Tcl_GetBoolean(interp, argv[2], &writable) != TCL_OK) { @@ -2768,12 +2789,94 @@ TestlinkCmd(dummy, interp, argc, argv) TCL_LINK_WIDE_INT | flag) != TCL_OK) { return TCL_ERROR; } + if (Tcl_GetBoolean(interp, argv[7], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "char", (char *) &charVar, + TCL_LINK_CHAR | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[8], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "uchar", (char *) &ucharVar, + TCL_LINK_UCHAR | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[9], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "short", (char *) &shortVar, + TCL_LINK_SHORT | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[10], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "ushort", (char *) &ushortVar, + TCL_LINK_USHORT | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[11], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "uint", (char *) &uintVar, + TCL_LINK_UINT | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[12], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "long", (char *) &longVar, + TCL_LINK_LONG | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[13], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "ulong", (char *) &ulongVar, + TCL_LINK_ULONG | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[14], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "float", (char *) &floatVar, + TCL_LINK_FLOAT | flag) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBoolean(interp, argv[15], &writable) != TCL_OK) { + return TCL_ERROR; + } + flag = (writable != 0) ? 0 : TCL_LINK_READ_ONLY; + if (Tcl_LinkVar(interp, "uwide", (char *) &uwideVar, + TCL_LINK_WIDE_UINT | flag) != TCL_OK) { + return TCL_ERROR; + } + } else if (strcmp(argv[1], "delete") == 0) { Tcl_UnlinkVar(interp, "int"); Tcl_UnlinkVar(interp, "real"); Tcl_UnlinkVar(interp, "bool"); Tcl_UnlinkVar(interp, "string"); Tcl_UnlinkVar(interp, "wide"); + Tcl_UnlinkVar(interp, "char"); + Tcl_UnlinkVar(interp, "uchar"); + Tcl_UnlinkVar(interp, "short"); + Tcl_UnlinkVar(interp, "ushort"); + Tcl_UnlinkVar(interp, "uint"); + Tcl_UnlinkVar(interp, "long"); + Tcl_UnlinkVar(interp, "ulong"); + Tcl_UnlinkVar(interp, "float"); + Tcl_UnlinkVar(interp, "uwide"); created = 0; } else if (strcmp(argv[1], "get") == 0) { TclFormatInt(buffer, intVar); @@ -2789,11 +2892,36 @@ TestlinkCmd(dummy, interp, argc, argv) tmp = Tcl_NewWideIntObj(wideVar); Tcl_AppendElement(interp, Tcl_GetString(tmp)); Tcl_DecrRefCount(tmp); + TclFormatInt(buffer, (int) charVar); + Tcl_AppendElement(interp, buffer); + TclFormatInt(buffer, (int) ucharVar); + Tcl_AppendElement(interp, buffer); + TclFormatInt(buffer, (int) shortVar); + Tcl_AppendElement(interp, buffer); + TclFormatInt(buffer, (int) ushortVar); + Tcl_AppendElement(interp, buffer); + TclFormatInt(buffer, (int) uintVar); + Tcl_AppendElement(interp, buffer); + tmp = Tcl_NewLongObj(longVar); + Tcl_AppendElement(interp, Tcl_GetString(tmp)); + Tcl_DecrRefCount(tmp); + tmp = Tcl_NewLongObj((long)ulongVar); + Tcl_AppendElement(interp, Tcl_GetString(tmp)); + Tcl_DecrRefCount(tmp); + Tcl_PrintDouble((Tcl_Interp *) NULL, (double)floatVar, buffer); + Tcl_AppendElement(interp, buffer); + tmp = Tcl_NewWideIntObj((Tcl_WideInt)uwideVar); + Tcl_AppendElement(interp, Tcl_GetString(tmp)); + Tcl_DecrRefCount(tmp); } else if (strcmp(argv[1], "set") == 0) { - if (argc != 7) { + int v; + + if (argc != 16) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ", argv[1], - " intValue realValue boolValue stringValue wideValue\"", + " intValue realValue boolValue stringValue wideValue", + " charValue ucharValue shortValue ushortValue uintValue", + " longValue ulongValue floatValue uwideValue\"", (char *) NULL); return TCL_ERROR; } @@ -2831,11 +2959,74 @@ TestlinkCmd(dummy, interp, argc, argv) } Tcl_DecrRefCount(tmp); } + if (argv[7][0]) { + if (Tcl_GetInt(interp, argv[7], &v) != TCL_OK) { + return TCL_ERROR; + } + charVar = (char) v; + } + if (argv[8][0]) { + if (Tcl_GetInt(interp, argv[8], &v) != TCL_OK) { + return TCL_ERROR; + } + ucharVar = (unsigned char) v; + } + if (argv[9][0]) { + if (Tcl_GetInt(interp, argv[9], &v) != TCL_OK) { + return TCL_ERROR; + } + shortVar = (short) v; + } + if (argv[10][0]) { + if (Tcl_GetInt(interp, argv[10], &v) != TCL_OK) { + return TCL_ERROR; + } + ushortVar = (unsigned short) v; + } + if (argv[11][0]) { + if (Tcl_GetInt(interp, argv[11], &v) != TCL_OK) { + return TCL_ERROR; + } + uintVar = (unsigned int) v; + } + if (argv[12][0]) { + if (Tcl_GetInt(interp, argv[12], &v) != TCL_OK) { + return TCL_ERROR; + } + longVar = (long) v; + } + if (argv[13][0]) { + if (Tcl_GetInt(interp, argv[13], &v) != TCL_OK) { + return TCL_ERROR; + } + ulongVar = (unsigned long) v; + } + if (argv[14][0]) { + double d; + if (Tcl_GetDouble(interp, argv[14], &d) != TCL_OK) { + return TCL_ERROR; + } + floatVar = (float) d; + } + if (argv[15][0]) { + Tcl_WideInt w; + tmp = Tcl_NewStringObj(argv[15], -1); + if (Tcl_GetWideIntFromObj(interp, tmp, &w) != TCL_OK) { + Tcl_DecrRefCount(tmp); + return TCL_ERROR; + } + Tcl_DecrRefCount(tmp); + uwideVar = (Tcl_WideUInt) w; + } } else if (strcmp(argv[1], "update") == 0) { - if (argc != 7) { + int v; + + if (argc != 16) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ", argv[1], - "intValue realValue boolValue stringValue wideValue\"", + " intValue realValue boolValue stringValue wideValue", + " charValue ucharValue shortValue ushortValue uintValue", + " longValue ulongValue floatValue uwideValue\"", (char *) NULL); return TCL_ERROR; } @@ -2878,6 +3069,74 @@ TestlinkCmd(dummy, interp, argc, argv) Tcl_DecrRefCount(tmp); Tcl_UpdateLinkedVar(interp, "wide"); } + if (argv[7][0]) { + if (Tcl_GetInt(interp, argv[7], &v) != TCL_OK) { + return TCL_ERROR; + } + charVar = (char) v; + Tcl_UpdateLinkedVar(interp, "char"); + } + if (argv[8][0]) { + if (Tcl_GetInt(interp, argv[8], &v) != TCL_OK) { + return TCL_ERROR; + } + ucharVar = (unsigned char) v; + Tcl_UpdateLinkedVar(interp, "uchar"); + } + if (argv[9][0]) { + if (Tcl_GetInt(interp, argv[9], &v) != TCL_OK) { + return TCL_ERROR; + } + shortVar = (short) v; + Tcl_UpdateLinkedVar(interp, "short"); + } + if (argv[10][0]) { + if (Tcl_GetInt(interp, argv[10], &v) != TCL_OK) { + return TCL_ERROR; + } + ushortVar = (unsigned short) v; + Tcl_UpdateLinkedVar(interp, "ushort"); + } + if (argv[11][0]) { + if (Tcl_GetInt(interp, argv[11], &v) != TCL_OK) { + return TCL_ERROR; + } + uintVar = (unsigned int) v; + Tcl_UpdateLinkedVar(interp, "uint"); + } + if (argv[12][0]) { + if (Tcl_GetInt(interp, argv[12], &v) != TCL_OK) { + return TCL_ERROR; + } + longVar = (long) v; + Tcl_UpdateLinkedVar(interp, "long"); + } + if (argv[13][0]) { + if (Tcl_GetInt(interp, argv[13], &v) != TCL_OK) { + return TCL_ERROR; + } + ulongVar = (unsigned long) v; + Tcl_UpdateLinkedVar(interp, "ulong"); + } + if (argv[14][0]) { + double d; + if (Tcl_GetDouble(interp, argv[14], &d) != TCL_OK) { + return TCL_ERROR; + } + floatVar = (float) d; + Tcl_UpdateLinkedVar(interp, "float"); + } + if (argv[15][0]) { + Tcl_WideInt w; + tmp = Tcl_NewStringObj(argv[15], -1); + if (Tcl_GetWideIntFromObj(interp, tmp, &w) != TCL_OK) { + Tcl_DecrRefCount(tmp); + return TCL_ERROR; + } + Tcl_DecrRefCount(tmp); + uwideVar = (Tcl_WideUInt) w; + Tcl_UpdateLinkedVar(interp, "uwide"); + } } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": should be create, delete, get, set, or update", diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 5a8f443..aa184a0 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtf.c,v 1.32.2.2 2005/08/02 18:16:11 dgp Exp $ + * RCS: @(#) $Id: tclUtf.c,v 1.32.2.3 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -168,45 +168,47 @@ Tcl_UniCharToUtf(ch, buf) buf[0] = (char) ch; return 1; } - if (ch <= 0x7FF) { - buf[1] = (char) ((ch | 0x80) & 0xBF); - buf[0] = (char) ((ch >> 6) | 0xC0); - return 2; - } - if (ch <= 0xFFFF) { + if (ch >= 0) { + if (ch <= 0x7FF) { + buf[1] = (char) ((ch | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 6) | 0xC0); + return 2; + } + if (ch <= 0xFFFF) { three: - buf[2] = (char) ((ch | 0x80) & 0xBF); - buf[1] = (char) (((ch >> 6) | 0x80) & 0xBF); - buf[0] = (char) ((ch >> 12) | 0xE0); - return 3; - } + buf[2] = (char) ((ch | 0x80) & 0xBF); + buf[1] = (char) (((ch >> 6) | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 12) | 0xE0); + return 3; + } #if TCL_UTF_MAX > 3 - if (ch <= 0x1FFFFF) { - buf[3] = (char) ((ch | 0x80) & 0xBF); - buf[2] = (char) (((ch >> 6) | 0x80) & 0xBF); - buf[1] = (char) (((ch >> 12) | 0x80) & 0xBF); - buf[0] = (char) ((ch >> 18) | 0xF0); - return 4; - } - if (ch <= 0x3FFFFFF) { - buf[4] = (char) ((ch | 0x80) & 0xBF); - buf[3] = (char) (((ch >> 6) | 0x80) & 0xBF); - buf[2] = (char) (((ch >> 12) | 0x80) & 0xBF); - buf[1] = (char) (((ch >> 18) | 0x80) & 0xBF); - buf[0] = (char) ((ch >> 24) | 0xF8); - return 5; - } - if (ch <= 0x7FFFFFFF) { - buf[5] = (char) ((ch | 0x80) & 0xBF); - buf[4] = (char) (((ch >> 6) | 0x80) & 0xBF); - buf[3] = (char) (((ch >> 12) | 0x80) & 0xBF); - buf[2] = (char) (((ch >> 18) | 0x80) & 0xBF); - buf[1] = (char) (((ch >> 24) | 0x80) & 0xBF); - buf[0] = (char) ((ch >> 30) | 0xFC); - return 6; - } + if (ch <= 0x1FFFFF) { + buf[3] = (char) ((ch | 0x80) & 0xBF); + buf[2] = (char) (((ch >> 6) | 0x80) & 0xBF); + buf[1] = (char) (((ch >> 12) | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 18) | 0xF0); + return 4; + } + if (ch <= 0x3FFFFFF) { + buf[4] = (char) ((ch | 0x80) & 0xBF); + buf[3] = (char) (((ch >> 6) | 0x80) & 0xBF); + buf[2] = (char) (((ch >> 12) | 0x80) & 0xBF); + buf[1] = (char) (((ch >> 18) | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 24) | 0xF8); + return 5; + } + if (ch <= 0x7FFFFFFF) { + buf[5] = (char) ((ch | 0x80) & 0xBF); + buf[4] = (char) (((ch >> 6) | 0x80) & 0xBF); + buf[3] = (char) (((ch >> 12) | 0x80) & 0xBF); + buf[2] = (char) (((ch >> 18) | 0x80) & 0xBF); + buf[1] = (char) (((ch >> 24) | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 30) | 0xFC); + return 6; + } #endif + } ch = 0xFFFD; goto three; diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 45bd2d8..77b8f81 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtil.c,v 1.51.2.18 2005/08/23 06:15:21 dgp Exp $ + * RCS: @(#) $Id: tclUtil.c,v 1.51.2.19 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -1039,8 +1039,14 @@ Tcl_ConcatObj(objc, objv) */ for (i = 0; i < objc; i++) { + List *listRepPtr; + objPtr = objv[i]; - if ((objPtr->typePtr != &tclListType) || (objPtr->bytes != NULL)) { + if (objPtr->typePtr != &tclListType) { + break; + } + listRepPtr = (List *) objPtr->internalRep.twoPtrValue.ptr1; + if (objPtr->bytes != NULL && !listRepPtr->canonicalFlag) { break; } } @@ -1056,6 +1062,7 @@ Tcl_ConcatObj(objc, objv) * INT_MAX tells us to always put the new stuff on the end. It * will be set right in Tcl_ListObjReplace. */ + Tcl_ListObjGetElements(NULL, objv[i], &listc, &listv); Tcl_ListObjReplace(NULL, objPtr, INT_MAX, 0, listc, listv); } diff --git a/library/tm.tcl b/library/tm.tcl index 5c05e27..2830ea6 100644 --- a/library/tm.tcl +++ b/library/tm.tcl @@ -353,7 +353,7 @@ proc ::tcl::tm::roots {paths} { for {set n $minor} {$n >= 0} {incr n -1} { path add [file normalize [file join $p ${major}.${n}]] } - path add [file normalize [file join $pa site-tcl]] + path add [file normalize [file join $p site-tcl]] } return } diff --git a/tests/eval.test b/tests/eval.test index 22de6af..a57936b 100644 --- a/tests/eval.test +++ b/tests/eval.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: eval.test,v 1.6 2004/05/19 12:23:13 dkf Exp $ +# RCS: @(#) $Id: eval.test,v 1.6.2.1 2005/09/09 18:48:40 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -58,6 +58,29 @@ test eval-2.5 {error in eval'ed command: setting errorInfo} { error \"test error\" }\"" +test eval-3.1 {eval and pure lists} { + eval [list list 1 2 3 4 5] +} {1 2 3 4 5} +test eval-3.2 {concatenating eval and pure lists} { + eval [list list 1] [list 2 3 4 5] +} {1 2 3 4 5} +test eval-3.3 {eval and canonical lists} { + set cmd [list list 1 2 3 4 5] + # Force existance of utf-8 rep + set dummy($cmd) $cmd + unset dummy($cmd) + eval $cmd +} {1 2 3 4 5} +test eval-3.4 {concatenating eval and canonical lists} { + set cmd [list list 1] + set cmd2 [list 2 3 4 5] + # Force existance of utf-8 rep + set dummy($cmd) $cmd + set dummy($cmd2) $cmd2 + unset dummy($cmd) dummy($cmd2) + eval $cmd $cmd2 +} {1 2 3 4 5} + # cleanup ::tcltest::cleanupTests return diff --git a/tests/link.test b/tests/link.test index 765f4b9..51f41aa 100644 --- a/tests/link.test +++ b/tests/link.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: link.test,v 1.7 2002/06/22 04:19:47 dgp Exp $ +# RCS: @(#) $Id: link.test,v 1.7.6.1 2005/09/09 18:48:40 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -26,57 +26,66 @@ foreach i {int real bool string} { } test link-1.1 {reading C variables from Tcl} {testlink} { testlink delete - testlink set 43 1.23 4 - 12341234 - testlink create 1 1 1 1 1 + testlink set 43 1.23 4 - 12341234 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 list $int $real $bool $string $wide } {43 1.23 1 NULL 12341234} test link-1.2 {reading C variables from Tcl} {testlink} { testlink delete - testlink create 1 1 1 1 1 - testlink set -3 2 0 "A long string with spaces" 43214321 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set -3 2 0 "A long string with spaces" 43214321 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 list $int $real $bool $string $wide $int $real $bool $string $wide } {-3 2.0 0 {A long string with spaces} 43214321 -3 2.0 0 {A long string with spaces} 43214321} test link-2.1 {writing C variables from Tcl} {testlink} { testlink delete - testlink set 43 1.21 4 - 56785678 - testlink create 1 1 1 1 1 + testlink set 43 1.21 4 - 56785678 64 250 30000 60000 0xbaadbeef 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 set int "00721" set real -10.5 set bool true set string abcdef set wide 135135 - concat [testlink get] $int $real $bool $string $wide -} {465 -10.5 1 abcdef 135135 00721 -10.5 true abcdef 135135} + set char 79 + set uchar 161 + set short 8000 + set ushort 40000 + set uint 0xc001babe + set long 34543 + set ulong 567890 + set float 1.0987654321 + set uwide 357357357357 + concat [testlink get] | $int $real $bool $string $wide $char $uchar $short $ushort $uint $long $ulong $float $uwide +} {465 -10.5 1 abcdef 135135 79 161 8000 40000 -1073628482 34543 567890 1.0987653732299805 357357357357 | 00721 -10.5 true abcdef 135135 79 161 8000 40000 0xc001babe 34543 567890 1.0987654321 357357357357} test link-2.2 {writing bad values into variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 1 1 1 1 1 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 list [catch {set int 09a} msg] $msg $int } {1 {can't set "int": variable must have integer value} 43} test link-2.3 {writing bad values into variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 1 1 1 1 1 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 list [catch {set real 1.x3} msg] $msg $real } {1 {can't set "real": variable must have real value} 1.23} test link-2.4 {writing bad values into variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 1 1 1 1 1 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 list [catch {set bool gorp} msg] $msg $bool } {1 {can't set "bool": variable must have boolean value} 1} test link-2.5 {writing bad values into variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 1 1 1 1 1 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 list [catch {set wide gorp} msg] $msg $bool } {1 {can't set "wide": variable must have integer value} 1} test link-3.1 {read-only variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 0 1 1 0 0 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 0 1 1 0 0 0 0 0 0 0 0 0 0 0 list [catch {set int 4} msg] $msg $int \ [catch {set real 10.6} msg] $msg $real \ [catch {set bool no} msg] $msg $bool \ @@ -85,8 +94,8 @@ test link-3.1 {read-only variables} {testlink} { } {1 {can't set "int": linked variable is read-only} 43 0 10.6 10.6 0 no no 1 {can't set "string": linked variable is read-only} NULL 1 {can't set "wide": linked variable is read-only} 56785678} test link-3.2 {read-only variables} {testlink} { testlink delete - testlink set 43 1.23 4 - 56785678 - testlink create 1 0 0 1 1 + testlink set 43 1.23 4 - 56785678 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 0 0 1 1 0 0 0 0 0 0 0 0 0 list [catch {set int 4} msg] $msg $int \ [catch {set real 10.6} msg] $msg $real \ [catch {set bool no} msg] $msg $bool \ @@ -96,8 +105,8 @@ test link-3.2 {read-only variables} {testlink} { test link-4.1 {unsetting linked variables} {testlink} { testlink delete - testlink set -6 -2.5 0 stringValue 13579 - testlink create 1 1 1 1 1 + testlink set -6 -2.5 0 stringValue 13579 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 unset int real bool string wide list [catch {set int} msg] $msg [catch {set real} msg] $msg \ [catch {set bool} msg] $msg [catch {set string} msg] $msg \ @@ -105,42 +114,51 @@ test link-4.1 {unsetting linked variables} {testlink} { } {0 -6 0 -2.5 0 0 0 stringValue 0 13579} test link-4.2 {unsetting linked variables} {testlink} { testlink delete - testlink set -6 -2.1 0 stringValue 97531 - testlink create 1 1 1 1 1 + testlink set -6 -2.1 0 stringValue 97531 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 unset int real bool string wide set int 102 set real 16 set bool true set string newValue set wide 333555 - testlink get + lrange [testlink get] 0 4 } {102 16.0 1 newValue 333555} test link-5.1 {unlinking variables} {testlink} { testlink delete - testlink set -6 -2.25 0 stringValue 13579 + testlink set -6 -2.25 0 stringValue 13579 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 testlink delete set int xx1 set real qrst set bool bogus set string 12345 set wide 875421 + set char skjdf + set uchar dslfjk + set short slkf + set ushort skrh + set uint sfdkfkh + set long srkjh + set ulong sjkg + set float dskjfbjfd + set uwide isdfsngs testlink get -} {-6 -2.25 0 stringValue 13579} +} {-6 -2.25 0 stringValue 13579 64 250 30000 60000 -1091585346 12321 32123 3.25 1231231234} test link-5.2 {unlinking variables} {testlink} { testlink delete - testlink set -6 -2.25 0 stringValue 97531 - testlink create 1 1 1 1 1 + testlink set -6 -2.25 0 stringValue 97531 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 testlink delete - testlink set 25 14.7 7 - 999999 - list $int $real $bool $string $wide -} {-6 -2.25 0 stringValue 97531} + testlink set 25 14.7 7 - 999999 65 251 30001 60001 0xbabebeef 12322 32124 3.125 12312312340 + list $int $real $bool $string $wide $char $uchar $short $ushort $uint $long $ulong $float $uwide +} {-6 -2.25 0 stringValue 97531 64 250 30000 60000 3203381950 12321 32123 3.25 1231231234} test link-6.1 {errors in setting up link} {testlink} { testlink delete catch {unset int} set int(44) 1 - list [catch {testlink create 1 1 1 1 1} msg] $msg + list [catch {testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1} msg] $msg } {1 {can't set "int": variable is array}} catch {unset int} @@ -150,8 +168,8 @@ test link-7.1 {access to linked variables via upvar} {testlink} { unset y } testlink delete - testlink create 1 0 0 0 0 - testlink set 14 {} {} {} {} + testlink create 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + testlink set 14 {} {} {} {} {} {} {} {} {} {} {} {} {} x list [catch {set int} msg] $msg } {0 14} @@ -161,10 +179,10 @@ test link-7.2 {access to linked variables via upvar} {testlink} { return [set y] } testlink delete - testlink create 1 0 0 0 0 - testlink set 0 {} {} {} {} + testlink create 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + testlink set 0 {} {} {} {} {} {} {} {} {} {} {} {} {} set int - testlink set 23 {} {} {} {} + testlink set 23 {} {} {} {} {} {} {} {} {} {} {} {} {} x list [x] $int } {23 23} @@ -174,8 +192,8 @@ test link-7.3 {access to linked variables via upvar} {testlink} { set y 44 } testlink delete - testlink create 0 0 0 0 0 - testlink set 11 {} {} {} {} + testlink create 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + testlink set 11 {} {} {} {} {} {} {} {} {} {} {} {} {} list [catch x msg] $msg $int } {1 {can't set "y": linked variable is read-only} 11} test link-7.4 {access to linked variables via upvar} {testlink} { @@ -184,8 +202,8 @@ test link-7.4 {access to linked variables via upvar} {testlink} { set y abc } testlink delete - testlink create 1 1 1 1 1 - testlink set -4 {} {} {} {} + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set -4 {} {} {} {} {} {} {} {} {} {} {} {} {} list [catch x msg] $msg $int } {1 {can't set "y": variable must have integer value} -4} test link-7.5 {access to linked variables via upvar} {testlink} { @@ -194,8 +212,8 @@ test link-7.5 {access to linked variables via upvar} {testlink} { set y abc } testlink delete - testlink create 1 1 1 1 1 - testlink set -4 16.75 {} {} {} + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set -4 16.75 {} {} {} {} {} {} {} {} {} {} {} {} list [catch x msg] $msg $real } {1 {can't set "y": variable must have real value} 16.75} test link-7.6 {access to linked variables via upvar} {testlink} { @@ -204,8 +222,8 @@ test link-7.6 {access to linked variables via upvar} {testlink} { set y abc } testlink delete - testlink create 1 1 1 1 1 - testlink set -4 16.3 1 {} {} + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set -4 16.3 1 {} {} {} {} {} {} {} {} {} {} {} list [catch x msg] $msg $bool } {1 {can't set "y": variable must have boolean value} 1} test link-7.7 {access to linked variables via upvar} {testlink} { @@ -214,8 +232,8 @@ test link-7.7 {access to linked variables via upvar} {testlink} { set y abc } testlink delete - testlink create 1 1 1 1 1 - testlink set -4 16.3 1 {} 778899 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set -4 16.3 1 {} 778899 {} {} {} {} {} {} {} {} {} list [catch x msg] $msg $wide } {1 {can't set "y": variable must have integer value} 778899} @@ -225,10 +243,10 @@ test link-8.1 {Tcl_UpdateLinkedVar procedure} {testlink} { lappend x $args $int $real $bool $string $wide } set x {} - testlink create 1 1 1 1 1 - testlink set 14 -2.0 0 xyzzy 995511 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set 14 -2.0 0 xyzzy 995511 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 trace var int w x - testlink update 32 4.0 3 abcd 113355 + testlink update 32 4.0 3 abcd 113355 65 251 30001 60001 0xbabebeef 12322 32124 3.125 12312312340 trace vdelete int w x set x } {{int {} w} 32 -2.0 0 xyzzy 995511} @@ -238,20 +256,22 @@ test link-8.2 {Tcl_UpdateLinkedVar procedure} {testlink} { lappend x $args $int $real $bool $string $wide } set x {} - testlink create 1 1 1 1 1 - testlink set 14 -2.0 0 xyzzy 995511 + testlink create 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + testlink set 14 -2.0 0 xyzzy 995511 64 250 30000 60000 0xbeefbabe 12321 32123 3.25 1231231234 testlink delete trace var int w x - testlink update 32 4.0 6 abcd 113355 + testlink update 32 4.0 6 abcd 113355 65 251 30001 60001 0xbabebeef 12322 32124 3.125 12312312340 trace vdelete int w x set x } {} test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} { - testlink create 0 0 0 0 0 - list [catch {testlink update 47 {} {} {} {}} msg] $msg $int + testlink create 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + list [catch { + testlink update 47 {} {} {} {} {} {} {} {} {} {} {} {} {} + } msg] $msg $int } {0 {} 47} -catch {testlink set 0 0 0 - 0} +catch {testlink set 0 0 0 - 0 0 0 0 0 0 0 0 0 0} catch {testlink delete} foreach i {int real bool string wide} { catch {unset $i} diff --git a/tests/tm.test b/tests/tm.test index 9f5a83a..8b1fe57 100644 --- a/tests/tm.test +++ b/tests/tm.test @@ -6,7 +6,7 @@ # Copyright (c) 2004 by Donal K. Fellows. # All rights reserved. # -# RCS: @(#) $Id: tm.test,v 1.5 2004/11/05 09:21:46 dkf Exp $ +# RCS: @(#) $Id: tm.test,v 1.5.2.1 2005/09/09 18:48:40 dgp Exp $ package require Tcl 8.5 if {"::tcltest" ni [namespace children]} { @@ -204,8 +204,8 @@ proc genpaths {base} { set base [file normalize $base] foreach {major minor} [split [info tclversion] .] break set results {} - lappend results [file join $base site-tcl] set base [file join $base tcl$major] + lappend results [file join $base site-tcl] for {set i 0} {$i <= $minor} {incr i} { lappend results [file join $base ${major}.$i] } diff --git a/tests/utf.test b/tests/utf.test index 56a3acb..ab97195 100644 --- a/tests/utf.test +++ b/tests/utf.test @@ -8,7 +8,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: utf.test,v 1.12 2003/10/08 15:24:21 dgp Exp $ +# RCS: @(#) $Id: utf.test,v 1.12.2.1 2005/09/09 18:48:40 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -29,6 +29,9 @@ test utf-1.3 {Tcl_UniCharToUtf: 2 byte sequences} { test utf-1.4 {Tcl_UniCharToUtf: 3 byte sequences} { set x "\u4e4e" } [bytestring "\xe4\xb9\x8e"] +test utf-1.5 {Tcl_UniCharToUtf: negative Tcl_UniChar} { + string length [format %c -1] +} 1 test utf-2.1 {Tcl_UtfToUniChar: low ascii} { string length "abc" diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 6226b6c..6de5a65 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixChan.c,v 1.53.2.5 2005/08/02 18:16:55 dgp Exp $ + * RCS: @(#) $Id: tclUnixChan.c,v 1.53.2.6 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" /* Internal definitions for Tcl. */ @@ -3364,7 +3364,7 @@ FileThreadActionProc (instanceData, action) *---------------------------------------------------------------------- */ -int +static int FileTruncateProc(instanceData, length) ClientData instanceData; Tcl_WideInt length; diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index f80624e..b9082f0 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixFile.c,v 1.44.2.1 2005/08/02 18:16:56 dgp Exp $ + * RCS: @(#) $Id: tclUnixFile.c,v 1.44.2.2 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -288,10 +288,12 @@ TclpMatchInDirectory(interp, resultPtr, pathPtr, pattern, types) d = opendir(native); /* INTL: Native. */ if (d == NULL) { Tcl_DStringFree(&ds); - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "couldn't read directory \"", - Tcl_DStringValue(&dsOrig), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "couldn't read directory \"", + Tcl_DStringValue(&dsOrig), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } Tcl_DStringFree(&dsOrig); Tcl_DecrRefCount(fileNamePtr); return TCL_ERROR; diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 5da8d3f..ff14770 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixSock.c,v 1.9.2.2 2005/08/02 18:16:57 dgp Exp $ + * RCS: @(#) $Id: tclUnixSock.c,v 1.9.2.3 2005/09/09 18:48:40 dgp Exp $ */ #include "tclInt.h" @@ -36,7 +36,7 @@ static ProcessGlobalValue hostName = *---------------------------------------------------------------------- */ -void +static void InitializeHostName(valuePtr, lengthPtr, encodingPtr) char **valuePtr; int *lengthPtr; diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 4e1679e..077d5b3 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinFile.c,v 1.72.2.3 2005/08/02 18:17:02 dgp Exp $ + * RCS: @(#) $Id: tclWinFile.c,v 1.72.2.4 2005/09/09 18:48:41 dgp Exp $ */ //#define _WIN32_WINNT 0x0500 @@ -1018,10 +1018,12 @@ TclpMatchInDirectory(interp, resultPtr, pathPtr, pattern, types) } TclWinConvertError(err); - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "couldn't read directory \"", - Tcl_DStringValue(&dsOrig), "\": ", - Tcl_PosixError(interp), (char *) NULL); + if (interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "couldn't read directory \"", + Tcl_DStringValue(&dsOrig), "\": ", + Tcl_PosixError(interp), (char *) NULL); + } Tcl_DStringFree(&dsOrig); return TCL_ERROR; } -- cgit v0.12