Tcl Source Code

Check-in [84d2435115]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:merge trunk
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dgp-refactor
Files: files | file ages | folders
SHA3-256: 84d2435115ce9fe1f0659e796f97c159ea5466d5bf3e3da934b2ccbadc80b444
User & Date: dgp 2019-03-15 15:51:08
Context
2019-03-18
15:46
merge trunk check-in: 810452fe39 user: dgp tags: dgp-refactor
2019-03-15
15:51
merge trunk check-in: 84d2435115 user: dgp tags: dgp-refactor
2019-03-14
20:03
merge-mark check-in: 80c345bf67 user: jan.nijtmans tags: trunk
2019-03-08
15:09
merge trunk check-in: 2886da4545 user: dgp tags: dgp-refactor
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to .travis.yml.

   118    118               - gcc-mingw-w64
   119    119               - gcc-multilib
   120    120               - wine
   121    121         env:
   122    122           - BUILD_DIR=win
   123    123           - CFGOPT=--host=i686-w64-mingw32
   124    124           - NO_DIRECT_TEST=1
          125  +    - os: linux
          126  +      dist: xenial
          127  +      compiler: i686-w64-mingw32-gcc
          128  +      addons:
          129  +        apt:
          130  +          packages:
          131  +            - gcc-mingw-w64-base
          132  +            - binutils-mingw-w64-i686
          133  +            - gcc-mingw-w64-i686
          134  +            - gcc-mingw-w64
          135  +            - gcc-multilib
          136  +            - wine
          137  +      env:
          138  +        - BUILD_DIR=win
          139  +        - CFGOPT="--host=i686-w64-mingw32 CFLAGS=-DTCL_UTF_MAX=6"
          140  +        - NO_DIRECT_TEST=1
   125    141   # Test with mingw-w64 (64 bit)
   126    142       - os: linux
   127    143         dist: xenial
   128    144         compiler: x86_64-w64-mingw32-gcc
   129    145         addons:
   130    146           apt:
   131    147             packages:
................................................................................
   134    150               - gcc-mingw-w64-x86-64
   135    151               - gcc-mingw-w64
   136    152               - wine
   137    153         env:
   138    154           - BUILD_DIR=win
   139    155           - CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit"
   140    156           - NO_DIRECT_TEST=1
          157  +    - os: linux
          158  +      dist: xenial
          159  +      compiler: x86_64-w64-mingw32-gcc
          160  +      addons:
          161  +        apt:
          162  +          packages:
          163  +            - gcc-mingw-w64-base
          164  +            - binutils-mingw-w64-x86-64
          165  +            - gcc-mingw-w64-x86-64
          166  +            - gcc-mingw-w64
          167  +            - wine
          168  +      env:
          169  +        - BUILD_DIR=win
          170  +        - CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit CFLAGS=-DTCL_UTF_MAX=6"
          171  +        - NO_DIRECT_TEST=1
   141    172   
   142    173   before_install:
   143    174     - export ERROR_ON_FAILURES=1
   144    175     - cd ${BUILD_DIR}
   145    176   install:
   146    177     - test -n "$NO_DIRECT_CONFIGURE" || ./configure ${CFGOPT}
   147    178   script:
   148    179     - make
   149    180     # The styles=develop avoids some weird problems on OSX
   150    181     - test -n "$NO_DIRECT_TEST" || make test styles=develop

Changes to generic/regcomp.c.

   202    202       const chr *stop;		/* end of string */
   203    203       const chr *savenow;		/* saved now and stop for "subroutine call" */
   204    204       const chr *savestop;
   205    205       int err;			/* error code (0 if none) */
   206    206       int cflags;			/* copy of compile flags */
   207    207       int lasttype;		/* type of previous token */
   208    208       int nexttype;		/* type of next token */
   209         -    chr nextvalue;		/* value (if any) of next token */
          209  +    int nextvalue;		/* value (if any) of next token */
   210    210       int lexcon;			/* lexical context type (see lex.c) */
   211    211       int nsubexp;		/* subexpression count */
   212    212       struct subre **subs;	/* subRE pointer vector */
   213         -    size_t nsubs;		/* length of vector */
          213  +    int nsubs;			/* length of vector */
   214    214       struct subre *sub10[10];	/* initial vector, enough for most */
   215    215       struct nfa *nfa;		/* the NFA */
   216    216       struct colormap *cm;	/* character color map */
   217    217       color nlcolor;		/* color of newline */
   218    218       struct state *wordchrs;	/* state in nfa holding word-char outarcs */
   219    219       struct subre *tree;		/* subexpression tree */
   220    220       struct subre *treechain;	/* all tree nodes allocated */
................................................................................
   283    283       regex_t *re,
   284    284       const chr *string,
   285    285       size_t len,
   286    286       int flags)
   287    287   {
   288    288       AllocVars(v);
   289    289       struct guts *g;
   290         -    int i;
   291         -    size_t j;
          290  +    int i, j;
   292    291       FILE *debug = (flags&REG_PROGRESS) ? stdout : NULL;
   293    292   #define	CNOERR()	{ if (ISERR()) return freev(v, v->err); }
   294    293   
   295    294       /*
   296    295        * Sanity checks.
   297    296        */
   298    297   
................................................................................
   473    472    */
   474    473   static void
   475    474   moresubs(
   476    475       struct vars *v,
   477    476       size_t wanted)			/* want enough room for this one */
   478    477   {
   479    478       struct subre **p;
   480         -    size_t n;
          479  +    int n;
   481    480   
   482    481       assert(wanted > 0 && wanted >= v->nsubs);
   483    482       n = wanted * 3 / 2 + 1;
   484    483       if (v->subs == v->sub10) {
   485    484   	p = (struct subre **) MALLOC(n * sizeof(struct subre *));
   486    485   	if (p != NULL) {
   487    486   	    memcpy(p, v->subs, v->nsubs * sizeof(struct subre *));
................................................................................
   793    792       struct state *s2;
   794    793   #define	ARCV(t, val)	newarc(v->nfa, t, val, lp, rp)
   795    794       int m, n;
   796    795       struct subre *atom;		/* atom's subtree */
   797    796       struct subre *t;
   798    797       int cap;			/* capturing parens? */
   799    798       int pos;			/* positive lookahead? */
   800         -    size_t subno;		/* capturing-parens or backref number */
          799  +    int subno;			/* capturing-parens or backref number */
   801    800       int atomtype;
   802    801       int qprefer;		/* quantifier short/long preference */
   803    802       int f;
   804    803       struct subre **atomp;	/* where the pointer to atom is */
   805    804   
   806    805       /*
   807    806        * Initial bookkeeping.

Changes to generic/regex.h.

   138    138       /* the rest is opaque pointers to hidden innards */
   139    139       char *re_guts;		/* `char *' is more portable than `void *' */
   140    140       char *re_fns;
   141    141   } regex_t;
   142    142   
   143    143   /* result reporting (may acquire more fields later) */
   144    144   typedef struct {
   145         -    size_t rm_so;		/* start of substring */
   146         -    size_t rm_eo;		/* end of substring */
          145  +    long rm_so;		/* start of substring */
          146  +    long rm_eo;		/* end of substring */
   147    147   } regmatch_t;
   148    148   
   149    149   /* supplementary control and reporting */
   150    150   typedef struct {
   151    151       regmatch_t rm_extend;	/* see REG_EXPECT */
   152    152   } rm_detail_t;
   153    153   

Changes to generic/regexec.c.

   168    168       rm_detail_t *details,
   169    169       size_t nmatch,
   170    170       regmatch_t pmatch[],
   171    171       int flags)
   172    172   {
   173    173       AllocVars(v);
   174    174       int st, backref;
   175         -    size_t n;
   176         -    size_t i;
          175  +    int n;
          176  +    int i;
   177    177   #define	LOCALMAT	20
   178    178       regmatch_t mat[LOCALMAT];
   179    179   #define LOCALDFAS	40
   180    180       struct dfa *subdfas[LOCALDFAS];
   181    181   
   182    182       /*
   183    183        * Sanity checks.
................................................................................
   232    232   	v->pmatch = pmatch;
   233    233       }
   234    234       v->details = details;
   235    235       v->start = (chr *)string;
   236    236       v->stop = (chr *)string + len;
   237    237       v->err = 0;
   238    238       assert(v->g->ntree >= 0);
   239         -    n = (size_t) v->g->ntree;
          239  +    n = v->g->ntree;
   240    240       if (n <= LOCALDFAS)
   241    241   	v->subdfas = subdfas;
   242    242       else
   243    243   	v->subdfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *));
   244    244       if (v->subdfas == NULL) {
   245    245   	if (v->pmatch != pmatch && v->pmatch != mat)
   246    246   	    FREE(v->pmatch);
................................................................................
   274    274       /*
   275    275        * Clean up.
   276    276        */
   277    277   
   278    278       if (v->pmatch != pmatch && v->pmatch != mat) {
   279    279   	FREE(v->pmatch);
   280    280       }
   281         -    n = (size_t) v->g->ntree;
          281  +    n = v->g->ntree;
   282    282       for (i = 0; i < n; i++) {
   283    283   	if (v->subdfas[i] != NULL)
   284    284   	    freeDFA(v->subdfas[i]);
   285    285       }
   286    286       if (v->subdfas != subdfas)
   287    287   	FREE(v->subdfas);
   288    288       FreeVars(v);
................................................................................
   885    885       assert(t->op == 'b');
   886    886       assert(n >= 0);
   887    887       assert((size_t)n < v->nmatch);
   888    888   
   889    889       MDEBUG(("cbackref n%d %d{%d-%d}\n", t->id, n, min, max));
   890    890   
   891    891       /* get the backreferenced string */
   892         -    if (v->pmatch[n].rm_so == (size_t)-1) {
          892  +    if (v->pmatch[n].rm_so == -1) {
   893    893   	return REG_NOMATCH;
   894    894       }
   895    895       brstring = v->start + v->pmatch[n].rm_so;
   896    896       brlen = v->pmatch[n].rm_eo - v->pmatch[n].rm_so;
   897    897   
   898    898       /* special cases for zero-length strings */
   899    899       if (brlen == 0) {

Changes to generic/tclBinary.c.

   636    636       size_t length;
   637    637       ByteArray *srcArrayPtr, *copyArrayPtr;
   638    638       Tcl_ObjIntRep ir;
   639    639   
   640    640       srcArrayPtr = GET_BYTEARRAY(TclFetchIntRep(srcPtr, &tclByteArrayType));
   641    641       length = srcArrayPtr->used;
   642    642   
   643         -    copyArrayPtr = ckalloc(BYTEARRAY_SIZE(length));
          643  +    copyArrayPtr = Tcl_Alloc(BYTEARRAY_SIZE(length));
   644    644       copyArrayPtr->used = length;
   645    645       copyArrayPtr->allocated = length;
   646    646       memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, length);
   647    647   
   648    648       SET_BYTEARRAY(&ir, copyArrayPtr);
   649    649       Tcl_StoreIntRep(copyPtr, &tclByteArrayType, &ir);
   650    650   }
................................................................................
  1387   1387       const char *format;	/* Pointer to current position in format
  1388   1388   				 * string. */
  1389   1389       Tcl_Obj *resultPtr = NULL;	/* Object holding result buffer. */
  1390   1390       unsigned char *buffer;	/* Start of result buffer. */
  1391   1391       const char *errorString;
  1392   1392       const char *str;
  1393   1393       int offset, size;
  1394         -    size_t length;
         1394  +    size_t length = 0;
  1395   1395   
  1396   1396       int i;
  1397   1397       Tcl_Obj *valuePtr, *elementPtr;
  1398   1398       Tcl_HashTable numberCacheHash;
  1399   1399       Tcl_HashTable *numberCachePtr;
  1400   1400   
  1401   1401       if (objc < 3) {
................................................................................
  2716   2716   {
  2717   2717       Tcl_Obj *resultObj;
  2718   2718       unsigned char *data, *start, *cursor;
  2719   2719       int rawLength, n, i, bits, index;
  2720   2720       int lineLength = 61;
  2721   2721       const unsigned char SingleNewline[] = { (unsigned char) '\n' };
  2722   2722       const unsigned char *wrapchar = SingleNewline;
  2723         -    size_t j, offset, count, wrapcharlen = sizeof(SingleNewline);
         2723  +    size_t j, offset, count = 0, wrapcharlen = sizeof(SingleNewline);
  2724   2724       enum { OPT_MAXLEN, OPT_WRAPCHAR };
  2725   2725       static const char *const optStrings[] = { "-maxlen", "-wrapchar", NULL };
  2726   2726   
  2727   2727       if (objc < 2 || objc%2 != 0) {
  2728   2728   	Tcl_WrongNumArgs(interp, 1, objv,
  2729   2729   		"?-maxlen len? ?-wrapchar char? data");
  2730   2730   	return TCL_ERROR;

Changes to generic/tclCmdAH.c.

   424    424       Tcl_Interp *interp,		/* Current interpreter. */
   425    425       int objc,			/* Number of arguments. */
   426    426       Tcl_Obj *const objv[])	/* Argument objects. */
   427    427   {
   428    428       Tcl_Obj *data;		/* Byte array to convert */
   429    429       Tcl_DString ds;		/* Buffer to hold the string */
   430    430       Tcl_Encoding encoding;	/* Encoding to use */
   431         -    size_t length;			/* Length of the byte array being converted */
          431  +    size_t length = 0;			/* Length of the byte array being converted */
   432    432       const char *bytesPtr;	/* Pointer to the first byte of the array */
   433    433   
   434    434       if (objc == 2) {
   435    435   	encoding = Tcl_GetEncoding(interp, NULL);
   436    436   	data = objv[1];
   437    437       } else if (objc == 3) {
   438    438   	if (Tcl_GetEncodingFromObj(interp, objv[1], &encoding) != TCL_OK) {

Changes to generic/tclCompCmds.c.

  1562   1562       if (Tcl_SplitList(NULL, Tcl_DStringValue(&buffer), &numVars,
  1563   1563   	    &argv) != TCL_OK) {
  1564   1564   	Tcl_DStringFree(&buffer);
  1565   1565   	return TclCompileBasic3ArgCmd(interp, parsePtr, cmdPtr, envPtr);
  1566   1566       }
  1567   1567       Tcl_DStringFree(&buffer);
  1568   1568       if (numVars != 2) {
  1569         -	Tcl_Free(argv);
         1569  +	Tcl_Free((void *)argv);
  1570   1570   	return TclCompileBasic3ArgCmd(interp, parsePtr, cmdPtr, envPtr);
  1571   1571       }
  1572   1572   
  1573   1573       nameChars = strlen(argv[0]);
  1574   1574       keyVarIndex = LocalScalar(argv[0], nameChars, envPtr);
  1575   1575       nameChars = strlen(argv[1]);
  1576   1576       valueVarIndex = LocalScalar(argv[1], nameChars, envPtr);
  1577         -    Tcl_Free(argv);
         1577  +    Tcl_Free((void *)argv);
  1578   1578   
  1579   1579       if ((keyVarIndex < 0) || (valueVarIndex < 0)) {
  1580   1580   	return TclCompileBasic3ArgCmd(interp, parsePtr, cmdPtr, envPtr);
  1581   1581       }
  1582   1582   
  1583   1583       /*
  1584   1584        * Allocate a temporary variable to store the iterator reference. The

Changes to generic/tclConfig.c.

   198    198       Tcl_Interp *interp,
   199    199       int objc,
   200    200       struct Tcl_Obj *const *objv)
   201    201   {
   202    202       QCCD *cdPtr = clientData;
   203    203       Tcl_Obj *pkgName = cdPtr->pkg;
   204    204       Tcl_Obj *pDB, *pkgDict, *val, *listPtr;
   205         -    size_t n;
          205  +    size_t n = 0;
   206    206       int index, m;
   207    207       static const char *const subcmdStrings[] = {
   208    208   	"get", "list", NULL
   209    209       };
   210    210       enum subcmds {
   211    211   	CFG_GET, CFG_LIST
   212    212       };

Changes to generic/tclEncoding.c.

   230    230   			    int *srcReadPtr, int *dstWrotePtr,
   231    231   			    int *dstCharsPtr);
   232    232   static int		TableToUtfProc(ClientData clientData, const char *src,
   233    233   			    int srcLen, int flags, Tcl_EncodingState *statePtr,
   234    234   			    char *dst, int dstLen, int *srcReadPtr,
   235    235   			    int *dstWrotePtr, int *dstCharsPtr);
   236    236   static size_t		unilen(const char *src);
   237         -static int		UnicodeToUtfProc(ClientData clientData,
          237  +static int		UniCharToUtfProc(ClientData clientData,
   238    238   			    const char *src, int srcLen, int flags,
   239    239   			    Tcl_EncodingState *statePtr, char *dst, int dstLen,
   240    240   			    int *srcReadPtr, int *dstWrotePtr,
   241    241   			    int *dstCharsPtr);
   242         -static int		UtfToUnicodeProc(ClientData clientData,
          242  +static int		UtfToUniCharProc(ClientData clientData,
   243    243   			    const char *src, int srcLen, int flags,
   244    244   			    Tcl_EncodingState *statePtr, char *dst, int dstLen,
   245    245   			    int *srcReadPtr, int *dstWrotePtr,
   246    246   			    int *dstCharsPtr);
   247    247   static int		UtfToUtfProc(ClientData clientData,
   248    248   			    const char *src, int srcLen, int flags,
   249    249   			    Tcl_EncodingState *statePtr, char *dst, int dstLen,
................................................................................
   592    592       type.fromUtfProc	= UtfIntToUtfExtProc;
   593    593       type.freeProc	= NULL;
   594    594       type.nullSize	= 1;
   595    595       type.clientData	= NULL;
   596    596       Tcl_CreateEncoding(&type);
   597    597   
   598    598       type.encodingName   = "unicode";
   599         -    type.toUtfProc	= UnicodeToUtfProc;
   600         -    type.fromUtfProc    = UtfToUnicodeProc;
          599  +    type.toUtfProc	= UniCharToUtfProc;
          600  +    type.fromUtfProc    = UtfToUniCharProc;
   601    601       type.freeProc	= NULL;
   602    602       type.nullSize	= 2;
   603    603       type.clientData	= NULL;
   604    604       Tcl_CreateEncoding(&type);
   605    605   
   606    606       /*
   607    607        * Need the iso8859-1 encoding in order to process binary data, so force
................................................................................
  1999   1999   		   Tcl_FreeEncoding((Tcl_Encoding) e);
  2000   2000   		   e = NULL;
  2001   2001   		}
  2002   2002   		est.encodingPtr = e;
  2003   2003   		Tcl_DStringAppend(&escapeData, (char *) &est, sizeof(est));
  2004   2004   	    }
  2005   2005   	}
  2006         -	Tcl_Free(argv);
         2006  +	Tcl_Free((void *)argv);
  2007   2007   	Tcl_DStringFree(&lineString);
  2008   2008       }
  2009   2009   
  2010   2010       size = sizeof(EscapeEncodingData) - sizeof(EscapeSubTable)
  2011   2011   	    + Tcl_DStringLength(&escapeData);
  2012   2012       dataPtr = Tcl_Alloc(size);
  2013   2013       dataPtr->initLen = strlen(init);
................................................................................
  2335   2335       *dstCharsPtr = numChars;
  2336   2336       return result;
  2337   2337   }
  2338   2338   
  2339   2339   /*
  2340   2340    *-------------------------------------------------------------------------
  2341   2341    *
  2342         - * UnicodeToUtfProc --
         2342  + * UniCharToUtfProc --
  2343   2343    *
  2344   2344    *	Convert from Unicode to UTF-8.
  2345   2345    *
  2346   2346    * Results:
  2347   2347    *	Returns TCL_OK if conversion was successful.
  2348   2348    *
  2349   2349    * Side effects:
  2350   2350    *	None.
  2351   2351    *
  2352   2352    *-------------------------------------------------------------------------
  2353   2353    */
  2354   2354   
  2355   2355   static int
  2356         -UnicodeToUtfProc(
         2356  +UniCharToUtfProc(
  2357   2357       ClientData clientData,	/* Not used. */
  2358   2358       const char *src,		/* Source string in Unicode. */
  2359   2359       int srcLen,			/* Source string length in bytes. */
  2360   2360       int flags,			/* Conversion control flags. */
  2361   2361       Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
  2362   2362   				 * information used during a piecewise
  2363   2363   				 * conversion. Contents of statePtr are
................................................................................
  2378   2378       int *dstCharsPtr)		/* Filled with the number of characters that
  2379   2379   				 * correspond to the bytes stored in the
  2380   2380   				 * output buffer. */
  2381   2381   {
  2382   2382       const char *srcStart, *srcEnd;
  2383   2383       const char *dstEnd, *dstStart;
  2384   2384       int result, numChars, charLimit = INT_MAX;
  2385         -    Tcl_UniChar *chPtr = (Tcl_UniChar *) statePtr;
         2385  +    unsigned short ch;
  2386   2386   
  2387         -    if (flags & TCL_ENCODING_START) {
  2388         -    	*statePtr = 0;
  2389         -    }
  2390   2387       if (flags & TCL_ENCODING_CHAR_LIMIT) {
  2391   2388   	charLimit = *dstCharsPtr;
  2392   2389       }
  2393   2390       result = TCL_OK;
  2394         -    if ((srcLen % sizeof(Tcl_UniChar)) != 0) {
         2391  +    if ((srcLen % sizeof(unsigned short)) != 0) {
  2395   2392   	result = TCL_CONVERT_MULTIBYTE;
  2396         -	srcLen /= sizeof(Tcl_UniChar);
  2397         -	srcLen *= sizeof(Tcl_UniChar);
         2393  +	srcLen /= sizeof(unsigned short);
         2394  +	srcLen *= sizeof(unsigned short);
  2398   2395       }
  2399   2396   
  2400   2397       srcStart = src;
  2401   2398       srcEnd = src + srcLen;
  2402   2399   
  2403   2400       dstStart = dst;
  2404   2401       dstEnd = dst + dstLen - TCL_UTF_MAX;
................................................................................
  2407   2404   	if (dst > dstEnd) {
  2408   2405   	    result = TCL_CONVERT_NOSPACE;
  2409   2406   	    break;
  2410   2407   	}
  2411   2408   
  2412   2409   	/*
  2413   2410   	 * Special case for 1-byte utf chars for speed. Make sure we work with
  2414         -	 * Tcl_UniChar-size data.
         2411  +	 * unsigned short-size data.
  2415   2412   	 */
  2416   2413   
  2417         -	*chPtr = *(Tcl_UniChar *)src;
  2418         -	if (*chPtr && *chPtr < 0x80) {
  2419         -	    *dst++ = (*chPtr & 0xFF);
         2414  +	ch = *(unsigned short *)src;
         2415  +	if (ch && ch < 0x80) {
         2416  +	    *dst++ = (ch & 0xFF);
  2420   2417   	} else {
  2421         -	    dst += Tcl_UniCharToUtf(*chPtr, dst);
         2418  +	    dst += Tcl_UniCharToUtf(ch, dst);
  2422   2419   	}
  2423         -	src += sizeof(Tcl_UniChar);
         2420  +	src += sizeof(unsigned short);
  2424   2421       }
  2425   2422   
  2426   2423       *srcReadPtr = src - srcStart;
  2427   2424       *dstWrotePtr = dst - dstStart;
  2428   2425       *dstCharsPtr = numChars;
  2429   2426       return result;
  2430   2427   }
  2431   2428   
  2432   2429   /*
  2433   2430    *-------------------------------------------------------------------------
  2434   2431    *
  2435         - * UtfToUnicodeProc --
         2432  + * UtfToUniCharProc --
  2436   2433    *
  2437   2434    *	Convert from UTF-8 to Unicode.
  2438   2435    *
  2439   2436    * Results:
  2440   2437    *	Returns TCL_OK if conversion was successful.
  2441   2438    *
  2442   2439    * Side effects:
  2443   2440    *	None.
  2444   2441    *
  2445   2442    *-------------------------------------------------------------------------
  2446   2443    */
  2447   2444   
  2448   2445   static int
  2449         -UtfToUnicodeProc(
         2446  +UtfToUniCharProc(
  2450   2447       ClientData clientData,	/* TableEncodingData that specifies
  2451   2448   				 * encoding. */
  2452   2449       const char *src,		/* Source string in UTF-8. */
  2453   2450       int srcLen,			/* Source string length in bytes. */
  2454   2451       int flags,			/* Conversion control flags. */
  2455   2452       Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
  2456   2453   				 * information used during a piecewise
................................................................................
  2510   2507   	/*
  2511   2508   	 * Need to handle this in a way that won't cause misalignment by
  2512   2509   	 * casting dst to a Tcl_UniChar. [Bug 1122671]
  2513   2510   	 */
  2514   2511   
  2515   2512   #ifdef WORDS_BIGENDIAN
  2516   2513   #if TCL_UTF_MAX > 4
  2517         -	*dst++ = (*chPtr >> 24);
  2518         -	*dst++ = ((*chPtr >> 16) & 0xFF);
  2519         -	*dst++ = ((*chPtr >> 8) & 0xFF);
  2520         -	*dst++ = (*chPtr & 0xFF);
         2514  +	if (*chPtr <= 0xFFFF) {
         2515  +	    *dst++ = (*chPtr >> 8);
         2516  +	    *dst++ = (*chPtr & 0xFF);
         2517  +	} else {
         2518  +	    *dst++ = ((*chPtr & 0x3) >> 8) | 0xDC;
         2519  +	    *dst++ = (*chPtr & 0xFF);
         2520  +	    *dst++ = (((*chPtr - 0x10000) >> 18) & 0x3) | 0xD8;
         2521  +	    *dst++ = (((*chPtr - 0x10000) >> 10) & 0xFF);
         2522  +	}
  2521   2523   #else
  2522   2524   	*dst++ = (*chPtr >> 8);
  2523   2525   	*dst++ = (*chPtr & 0xFF);
  2524   2526   #endif
  2525   2527   #else
  2526   2528   #if TCL_UTF_MAX > 4
  2527         -	*dst++ = (*chPtr & 0xFF);
  2528         -	*dst++ = ((*chPtr >> 8) & 0xFF);
  2529         -	*dst++ = ((*chPtr >> 16) & 0xFF);
  2530         -	*dst++ = (*chPtr >> 24);
         2529  +	if (*chPtr <= 0xFFFF) {
         2530  +	    *dst++ = (*chPtr & 0xFF);
         2531  +	    *dst++ = (*chPtr >> 8);
         2532  +	} else {
         2533  +	    *dst++ = (((*chPtr - 0x10000) >> 10) & 0xFF);
         2534  +	    *dst++ = (((*chPtr - 0x10000) >> 18) & 0x3) | 0xD8;
         2535  +	    *dst++ = (*chPtr & 0xFF);
         2536  +	    *dst++ = ((*chPtr & 0x3) >> 8) | 0xDC;
         2537  +	}
  2531   2538   #else
  2532   2539   	*dst++ = (*chPtr & 0xFF);
  2533   2540   	*dst++ = (*chPtr >> 8);
  2534   2541   #endif
  2535   2542   #endif
  2536   2543       }
  2537   2544       *srcReadPtr = src - srcStart;

Changes to generic/tclEnsemble.c.

  1641   1641   	}
  1642   1642   	Tcl_SetEnsembleMappingDict(interp, ensemble, mapDict);
  1643   1643       }
  1644   1644   
  1645   1645       Tcl_DStringFree(&buf);
  1646   1646       Tcl_DStringFree(&hiddenBuf);
  1647   1647       if (nameParts != NULL) {
  1648         -	Tcl_Free(nameParts);
         1648  +	Tcl_Free((void *)nameParts);
  1649   1649       }
  1650   1650       return ensemble;
  1651   1651   }
  1652   1652   
  1653   1653   /*
  1654   1654    *----------------------------------------------------------------------
  1655   1655    *

Changes to generic/tclExecute.c.

  5283   5283   
  5284   5284   	    ustring1 = TclGetUnicodeFromObj(valuePtr, &slength);
  5285   5285   	    ustring2 = TclGetUnicodeFromObj(value2Ptr, &length2);
  5286   5286   	    match = TclUniCharMatch(ustring1, slength, ustring2, length2,
  5287   5287   		    nocase);
  5288   5288   	} else if (TclIsPureByteArray(valuePtr) && !nocase) {
  5289   5289   	    unsigned char *bytes1, *bytes2;
  5290         -	    size_t wlen1, wlen2;
         5290  +	    size_t wlen1 = 0, wlen2 = 0;
  5291   5291   
  5292   5292   	    bytes1 = TclGetByteArrayFromObj(valuePtr, &wlen1);
  5293   5293   	    bytes2 = TclGetByteArrayFromObj(value2Ptr, &wlen2);
  5294   5294   	    match = TclByteArrayMatch(bytes1, wlen1, bytes2, wlen2, 0);
  5295   5295   	} else {
  5296   5296   	    match = Tcl_StringCaseMatch(TclGetString(valuePtr),
  5297   5297   		    TclGetString(value2Ptr), nocase);

Changes to generic/tclIO.c.

  4184   4184       /*
  4185   4185        * Always use the topmost channel of the stack
  4186   4186        */
  4187   4187   
  4188   4188       Channel *chanPtr;
  4189   4189       ChannelState *statePtr;	/* State info for channel */
  4190   4190       const char *src;
  4191         -    size_t srcLen;
         4191  +    size_t srcLen = 0;
  4192   4192   
  4193   4193       statePtr = ((Channel *) chan)->state;
  4194   4194       chanPtr = statePtr->topChanPtr;
  4195   4195   
  4196   4196       if (CheckChannelErrors(statePtr, TCL_WRITABLE) != 0) {
  4197   4197   	return TCL_IO_FAILURE;
  4198   4198       }
................................................................................
  4404   4404   	     * When translating from UTF-8 to external encoding, we allowed
  4405   4405   	     * the translation to produce a character that crossed the end of
  4406   4406   	     * the output buffer, so that we would get a completely full
  4407   4407   	     * buffer before flushing it. The extra bytes will be moved to the
  4408   4408   	     * beginning of the next buffer.
  4409   4409   	     */
  4410   4410   
  4411         -	    saved = -SpaceLeft(bufPtr);
         4411  +	    saved = 1 + ~SpaceLeft(bufPtr);
  4412   4412   	    memcpy(safe, dst + dstLen, saved);
  4413   4413   	    bufPtr->nextAdded = bufPtr->bufLength;
  4414   4414   	}
  4415   4415   
  4416   4416   	if ((srcLen + saved == 0) && (result == TCL_OK)) {
  4417   4417   	    endEncoding = 0;
  4418   4418   	}
................................................................................
  4937   4937   				 * object as UTF-8 characters. */
  4938   4938   {
  4939   4939       Channel *chanPtr = (Channel *) chan;
  4940   4940       ChannelState *statePtr = chanPtr->state;
  4941   4941   				/* State info for channel */
  4942   4942       ChannelBuffer *bufPtr;
  4943   4943       int inEofChar, skip, copiedTotal, oldFlags, oldRemoved;
  4944         -    size_t rawLen, byteLen, oldLength;
         4944  +    size_t rawLen, byteLen = 0, oldLength;
  4945   4945       int eolChar;
  4946   4946       unsigned char *dst, *dstEnd, *eol, *eof, *byteArray;
  4947   4947   
  4948   4948       /*
  4949   4949        * This operation should occur at the top of a channel stack.
  4950   4950        */
  4951   4951   
................................................................................
  7668   7668   	argc--;
  7669   7669   	for (i = 0; i < argc; i++) {
  7670   7670   	    Tcl_AppendPrintfToObj(errObj, "-%s, ", argv[i]);
  7671   7671   	}
  7672   7672   	Tcl_AppendPrintfToObj(errObj, "or -%s", argv[i]);
  7673   7673           Tcl_SetObjResult(interp, errObj);
  7674   7674   	Tcl_DStringFree(&ds);
  7675         -	Tcl_Free(argv);
         7675  +	Tcl_Free((void *)argv);
  7676   7676       }
  7677   7677       Tcl_SetErrno(EINVAL);
  7678   7678       return TCL_ERROR;
  7679   7679   }
  7680   7680   
  7681   7681   /*
  7682   7682    *----------------------------------------------------------------------
................................................................................
  8059   8059   
  8060   8060   	    if (inValue & 0x80 || outValue & 0x80) {
  8061   8061   		if (interp) {
  8062   8062   		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  8063   8063                               "bad value for -eofchar: must be non-NUL ASCII"
  8064   8064                               " character", -1));
  8065   8065   		}
  8066         -		Tcl_Free(argv);
         8066  +		Tcl_Free((void *)argv);
  8067   8067   		return TCL_ERROR;
  8068   8068   	    }
  8069   8069   	    if (GotFlag(statePtr, TCL_READABLE)) {
  8070   8070   		statePtr->inEofChar = inValue;
  8071   8071   	    }
  8072   8072   	    if (GotFlag(statePtr, TCL_WRITABLE)) {
  8073   8073   		statePtr->outEofChar = outValue;
................................................................................
  8074   8074   	    }
  8075   8075   	} else {
  8076   8076   	    if (interp) {
  8077   8077   		Tcl_SetObjResult(interp, Tcl_NewStringObj(
  8078   8078   			"bad value for -eofchar: should be a list of zero,"
  8079   8079   			" one, or two elements", -1));
  8080   8080   	    }
  8081         -	    Tcl_Free(argv);
         8081  +	    Tcl_Free((void *)argv);
  8082   8082   	    return TCL_ERROR;
  8083   8083   	}
  8084   8084   	if (argv != NULL) {
  8085         -	    Tcl_Free(argv);
         8085  +	    Tcl_Free((void *)argv);
  8086   8086   	}
  8087   8087   
  8088   8088   	/*
  8089   8089   	 * [Bug 930851] Reset EOF and BLOCKED flags. Changing the character
  8090   8090   	 * which signals eof can transform a current eof condition into a 'go
  8091   8091   	 * ahead'. Ditto for blocked.
  8092   8092   	 */
................................................................................
  8112   8112   	    writeMode = GotFlag(statePtr, TCL_WRITABLE) ? argv[1] : NULL;
  8113   8113   	} else {
  8114   8114   	    if (interp) {
  8115   8115   		Tcl_SetObjResult(interp, Tcl_NewStringObj(
  8116   8116   			"bad value for -translation: must be a one or two"
  8117   8117   			" element list", -1));
  8118   8118   	    }
  8119         -	    Tcl_Free(argv);
         8119  +	    Tcl_Free((void *)argv);
  8120   8120   	    return TCL_ERROR;
  8121   8121   	}
  8122   8122   
  8123   8123   	if (readMode) {
  8124   8124   	    TclEolTranslation translation;
  8125   8125   
  8126   8126   	    if (*readMode == '\0') {
................................................................................
  8142   8142   		translation = TCL_PLATFORM_TRANSLATION;
  8143   8143   	    } else {
  8144   8144   		if (interp) {
  8145   8145   		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  8146   8146   			    "bad value for -translation: must be one of "
  8147   8147                               "auto, binary, cr, lf, crlf, or platform", -1));
  8148   8148   		}
  8149         -		Tcl_Free(argv);
         8149  +		Tcl_Free((void *)argv);
  8150   8150   		return TCL_ERROR;
  8151   8151   	    }
  8152   8152   
  8153   8153   	    /*
  8154   8154   	     * Reset the EOL flags since we need to look at any buffered data
  8155   8155   	     * to see if the new translation mode allows us to complete the
  8156   8156   	     * line.
................................................................................
  8192   8192   		statePtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
  8193   8193   	    } else {
  8194   8194   		if (interp) {
  8195   8195   		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  8196   8196   			    "bad value for -translation: must be one of "
  8197   8197                               "auto, binary, cr, lf, crlf, or platform", -1));
  8198   8198   		}
  8199         -		Tcl_Free(argv);
         8199  +		Tcl_Free((void *)argv);
  8200   8200   		return TCL_ERROR;
  8201   8201   	    }
  8202   8202   	}
  8203         -	Tcl_Free(argv);
         8203  +	Tcl_Free((void *)argv);
  8204   8204   	return TCL_OK;
  8205   8205       } else if (chanPtr->typePtr->setOptionProc != NULL) {
  8206   8206   	return chanPtr->typePtr->setOptionProc(chanPtr->instanceData, interp,
  8207   8207   		optionName, newValue);
  8208   8208       } else {
  8209   8209   	return Tcl_BadChannelOption(interp, optionName, NULL);
  8210   8210       }

Changes to generic/tclIOCmd.c.

  1161   1161   		break;
  1162   1162   	    }
  1163   1163   	    chan = Tcl_OpenCommandChannel(interp, cmdObjc, cmdArgv, flags);
  1164   1164   	    if (binary && chan) {
  1165   1165   		Tcl_SetChannelOption(interp, chan, "-translation", "binary");
  1166   1166   	    }
  1167   1167   	}
  1168         -	Tcl_Free(cmdArgv);
         1168  +	Tcl_Free((void *)cmdArgv);
  1169   1169       }
  1170   1170       if (chan == NULL) {
  1171   1171   	return TCL_ERROR;
  1172   1172       }
  1173   1173       Tcl_RegisterChannel(interp, chan);
  1174   1174       Tcl_SetObjResult(interp, Tcl_NewStringObj(Tcl_GetChannelName(chan), -1));
  1175   1175       return TCL_OK;

Changes to generic/tclIOGT.c.

   374    374   				 * callback is sent to the underlying channel
   375    375   				 * or not. */
   376    376       int preserve)		/* Flag. If true the procedure will preserve
   377    377   				 * the result state of all accessed
   378    378   				 * interpreters. */
   379    379   {
   380    380       Tcl_Obj *resObj;		/* See below, switch (transmit). */
   381         -    size_t resLen;
          381  +    size_t resLen = 0;
   382    382       unsigned char *resBuf;
   383    383       Tcl_InterpState state = NULL;
   384    384       int res = TCL_OK;
   385    385       Tcl_Obj *command = TclListObjCopy(NULL, dataPtr->command);
   386    386       Tcl_Interp *eval = dataPtr->interp;
   387    387   
   388    388       Tcl_Preserve(eval);

Changes to generic/tclIORChan.c.

  1255   1255       ClientData clientData,
  1256   1256       char *buf,
  1257   1257       int toRead,
  1258   1258       int *errorCodePtr)
  1259   1259   {
  1260   1260       ReflectedChannel *rcPtr = clientData;
  1261   1261       Tcl_Obj *toReadObj;
  1262         -    size_t bytec;			/* Number of returned bytes */
         1262  +    size_t bytec = 0;		/* Number of returned bytes */
  1263   1263       unsigned char *bytev;	/* Array of returned bytes */
  1264   1264       Tcl_Obj *resObj;		/* Result data for 'read' */
  1265   1265   
  1266   1266       /*
  1267   1267        * Are we in the correct thread?
  1268   1268        */
  1269   1269   
................................................................................
  2994   2994   	    }
  2995   2995   	    paramPtr->input.toRead = TCL_IO_FAILURE;
  2996   2996   	} else {
  2997   2997   	    /*
  2998   2998   	     * Process a regular result.
  2999   2999   	     */
  3000   3000   
  3001         -	    size_t bytec;			/* Number of returned bytes */
         3001  +	    size_t bytec = 0;		/* Number of returned bytes */
  3002   3002   	    unsigned char *bytev;	/* Array of returned bytes */
  3003   3003   
  3004   3004   	    bytev = TclGetByteArrayFromObj(resObj, &bytec);
  3005   3005   
  3006   3006   	    if (paramPtr->input.toRead < bytec) {
  3007   3007   		ForwardSetStaticError(paramPtr, msg_read_toomuch);
  3008   3008   		paramPtr->input.toRead = TCL_IO_FAILURE;

Changes to generic/tclIORTrans.c.

  2593   2593   	    paramPtr->transform.size = TCL_AUTO_LENGTH;
  2594   2594   	} else {
  2595   2595   	    /*
  2596   2596   	     * Process a regular return. Contains the transformation result.
  2597   2597   	     * Sent it back to the request originator.
  2598   2598   	     */
  2599   2599   
  2600         -	    size_t bytec;		/* Number of returned bytes */
         2600  +	    size_t bytec = 0;	/* Number of returned bytes */
  2601   2601   	    unsigned char *bytev;
  2602   2602   				/* Array of returned bytes */
  2603   2603   
  2604   2604   	    bytev = TclGetByteArrayFromObj(resObj, &bytec);
  2605   2605   
  2606   2606   	    paramPtr->transform.size = bytec;
  2607   2607   
................................................................................
  2627   2627   	    paramPtr->transform.size = TCL_AUTO_LENGTH;
  2628   2628   	} else {
  2629   2629   	    /*
  2630   2630   	     * Process a regular return. Contains the transformation result.
  2631   2631   	     * Sent it back to the request originator.
  2632   2632   	     */
  2633   2633   
  2634         -	    size_t bytec;		/* Number of returned bytes */
         2634  +	    size_t bytec = 0;	/* Number of returned bytes */
  2635   2635   	    unsigned char *bytev;
  2636   2636   				/* Array of returned bytes */
  2637   2637   
  2638   2638   	    bytev = TclGetByteArrayFromObj(resObj, &bytec);
  2639   2639   
  2640   2640   	    paramPtr->transform.size = bytec;
  2641   2641   
................................................................................
  2657   2657   	    paramPtr->transform.size = TCL_AUTO_LENGTH;
  2658   2658   	} else {
  2659   2659   	    /*
  2660   2660   	     * Process a regular return. Contains the transformation result.
  2661   2661   	     * Sent it back to the request originator.
  2662   2662   	     */
  2663   2663   
  2664         -	    size_t bytec;		/* Number of returned bytes */
         2664  +	    size_t bytec = 0;	/* Number of returned bytes */
  2665   2665   	    unsigned char *bytev; /* Array of returned bytes */
  2666   2666   
  2667   2667   	    bytev = TclGetByteArrayFromObj(resObj, &bytec);
  2668   2668   
  2669   2669   	    paramPtr->transform.size = bytec;
  2670   2670   
  2671   2671   	    if (bytec > 0) {
................................................................................
  2683   2683   	    paramPtr->transform.size = TCL_AUTO_LENGTH;
  2684   2684   	} else {
  2685   2685   	    /*
  2686   2686   	     * Process a regular return. Contains the transformation result.
  2687   2687   	     * Sent it back to the request originator.
  2688   2688   	     */
  2689   2689   
  2690         -	    size_t bytec;		/* Number of returned bytes */
         2690  +	    size_t bytec = 0;	/* Number of returned bytes */
  2691   2691   	    unsigned char *bytev;
  2692   2692   				/* Array of returned bytes */
  2693   2693   
  2694   2694   	    bytev = TclGetByteArrayFromObj(resObj, &bytec);
  2695   2695   
  2696   2696   	    paramPtr->transform.size = bytec;
  2697   2697   
................................................................................
  3076   3076   static int
  3077   3077   TransformRead(
  3078   3078       ReflectedTransform *rtPtr,
  3079   3079       int *errorCodePtr,
  3080   3080       Tcl_Obj *bufObj)
  3081   3081   {
  3082   3082       Tcl_Obj *resObj;
  3083         -    size_t bytec;			/* Number of returned bytes */
         3083  +    size_t bytec = 0;		/* Number of returned bytes */
  3084   3084       unsigned char *bytev;	/* Array of returned bytes */
  3085   3085   
  3086   3086       /*
  3087   3087        * Are we in the correct thread?
  3088   3088        */
  3089   3089   
  3090   3090   #if TCL_THREADS
................................................................................
  3131   3131       ReflectedTransform *rtPtr,
  3132   3132       int *errorCodePtr,
  3133   3133       unsigned char *buf,
  3134   3134       int toWrite)
  3135   3135   {
  3136   3136       Tcl_Obj *bufObj;
  3137   3137       Tcl_Obj *resObj;
  3138         -    size_t bytec;			/* Number of returned bytes */
         3138  +    size_t bytec = 0;		/* Number of returned bytes */
  3139   3139       unsigned char *bytev;	/* Array of returned bytes */
  3140   3140       int res;
  3141   3141   
  3142   3142       /*
  3143   3143        * Are we in the correct thread?
  3144   3144        */
  3145   3145   
................................................................................
  3198   3198   
  3199   3199   static int
  3200   3200   TransformDrain(
  3201   3201       ReflectedTransform *rtPtr,
  3202   3202       int *errorCodePtr)
  3203   3203   {
  3204   3204       Tcl_Obj *resObj;
  3205         -    size_t bytec;			/* Number of returned bytes */
         3205  +    size_t bytec = 0;		/* Number of returned bytes */
  3206   3206       unsigned char *bytev;	/* Array of returned bytes */
  3207   3207   
  3208   3208       /*
  3209   3209        * Are we in the correct thread?
  3210   3210        */
  3211   3211   
  3212   3212   #if TCL_THREADS
................................................................................
  3247   3247   static int
  3248   3248   TransformFlush(
  3249   3249       ReflectedTransform *rtPtr,
  3250   3250       int *errorCodePtr,
  3251   3251       int op)
  3252   3252   {
  3253   3253       Tcl_Obj *resObj;
  3254         -    size_t bytec;			/* Number of returned bytes */
         3254  +    size_t bytec = 0;		/* Number of returned bytes */
  3255   3255       unsigned char *bytev;	/* Array of returned bytes */
  3256   3256       int res;
  3257   3257   
  3258   3258       /*
  3259   3259        * Are we in the correct thread?
  3260   3260        */
  3261   3261   

Changes to generic/tclIOUtil.c.

  1663   1663   	    mode |= O_NOCTTY;
  1664   1664   #else
  1665   1665   	    if (interp != NULL) {
  1666   1666   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1667   1667   			"access mode \"%s\" not supported by this system",
  1668   1668   			flag));
  1669   1669   	    }
  1670         -	    Tcl_Free(modeArgv);
         1670  +	    Tcl_Free((void *)modeArgv);
  1671   1671   	    return -1;
  1672   1672   #endif
  1673   1673   
  1674   1674   	} else if ((c == 'N') && (strcmp(flag, "NONBLOCK") == 0)) {
  1675   1675   #ifdef O_NONBLOCK
  1676   1676   	    mode |= O_NONBLOCK;
  1677   1677   #else
  1678   1678   	    if (interp != NULL) {
  1679   1679   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1680   1680   			"access mode \"%s\" not supported by this system",
  1681   1681   			flag));
  1682   1682   	    }
  1683         -	    Tcl_Free(modeArgv);
         1683  +	    Tcl_Free((void *)modeArgv);
  1684   1684   	    return -1;
  1685   1685   #endif
  1686   1686   
  1687   1687   	} else if ((c == 'T') && (strcmp(flag, "TRUNC") == 0)) {
  1688   1688   	    mode |= O_TRUNC;
  1689   1689   	} else if ((c == 'B') && (strcmp(flag, "BINARY") == 0)) {
  1690   1690   	    *binaryPtr = 1;
................................................................................
  1692   1692   
  1693   1693   	    if (interp != NULL) {
  1694   1694   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1695   1695   			"invalid access mode \"%s\": must be RDONLY, WRONLY, "
  1696   1696   			"RDWR, APPEND, BINARY, CREAT, EXCL, NOCTTY, NONBLOCK,"
  1697   1697   			" or TRUNC", flag));
  1698   1698   	    }
  1699         -	    Tcl_Free(modeArgv);
         1699  +	    Tcl_Free((void *)modeArgv);
  1700   1700   	    return -1;
  1701   1701   	}
  1702   1702       }
  1703   1703   
  1704         -    Tcl_Free(modeArgv);
         1704  +    Tcl_Free((void *)modeArgv);
  1705   1705   
  1706   1706       if (!gotRW) {
  1707   1707   	if (interp != NULL) {
  1708   1708   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  1709   1709   		    "access mode must include either RDONLY, WRONLY, or RDWR",
  1710   1710   		    -1));
  1711   1711   	}
................................................................................
  4695   4695   
  4696   4696   /*
  4697   4697    *---------------------------------------------------------------------------
  4698   4698    *
  4699   4699    * Tcl_FSGetNativePath --
  4700   4700    *
  4701   4701    *	This function is for use by the Win/Unix native filesystems, so that
  4702         - *	they can easily retrieve the native (char* or TCHAR*) representation
         4702  + *	they can easily retrieve the native (char* or WCHAR*) representation
  4703   4703    *	of a path. Other filesystems will probably want to implement similar
  4704   4704    *	functions. They basically act as a safety net around
  4705   4705    *	Tcl_FSGetInternalRep. Normally your file-system functions will always
  4706   4706    *	be called with path objects already converted to the correct
  4707   4707    *	filesystem, but if for some reason they are called directly (i.e. by
  4708   4708    *	functions not in this file), then one cannot necessarily guarantee
  4709   4709    *	that the path object pointer is from the correct filesystem.

Changes to generic/tclIndexObj.c.

   134    134       tablePtr = Tcl_Alloc((objc + 1) * sizeof(char *));
   135    135       for (t = 0; t < objc; t++) {
   136    136   	if (objv[t] == objPtr) {
   137    137   	    /*
   138    138   	     * An exact match is always chosen, so we can stop here.
   139    139   	     */
   140    140   
   141         -	    Tcl_Free(tablePtr);
          141  +	    Tcl_Free((void *)tablePtr);
   142    142   	    *indexPtr = t;
   143    143   	    return TCL_OK;
   144    144   	}
   145    145   
   146    146   	tablePtr[t] = TclGetString(objv[t]);
   147    147       }
   148    148       tablePtr[objc] = NULL;
   149    149   
   150    150       result = Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr,
   151    151   	    sizeof(char *), msg, flags | INDEX_TEMP_TABLE, indexPtr);
   152    152   
   153         -    Tcl_Free(tablePtr);
          153  +    Tcl_Free((void *)tablePtr);
   154    154   
   155    155       return result;
   156    156   }
   157    157   
   158    158   /*
   159    159    *----------------------------------------------------------------------
   160    160    *

Changes to generic/tclInt.h.

  3271   3271   			    const char *trim, size_t numTrim);
  3272   3272   MODULE_SCOPE size_t	TclTrimRight(const char *bytes, size_t numBytes,
  3273   3273   			    const char *trim, size_t numTrim);
  3274   3274   MODULE_SCOPE const char*TclGetCommandTypeName(Tcl_Command command);
  3275   3275   MODULE_SCOPE void	TclRegisterCommandTypeName(
  3276   3276   			    Tcl_ObjCmdProc *implementationProc,
  3277   3277   			    const char *nameStr);
         3278  +#if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
         3279  +MODULE_SCOPE int TclUtfToWChar(const char *src, WCHAR *chPtr);
         3280  +MODULE_SCOPE char *	TclWCharToUtfDString(const WCHAR *uniStr,
         3281  +			    int uniLength, Tcl_DString *dsPtr);
         3282  +MODULE_SCOPE WCHAR * TclUtfToWCharDString(const char *src,
         3283  +			    int length, Tcl_DString *dsPtr);
         3284  +#else
         3285  +#   define TclUtfToWChar TclUtfToUniChar
         3286  +#   define TclWCharToUtfDString Tcl_UniCharToUtfDString
         3287  +#   define TclUtfToWCharDString Tcl_UtfToUniCharDString
         3288  +#endif
  3278   3289   MODULE_SCOPE int	TclUtfCmp(const char *cs, const char *ct);
  3279   3290   MODULE_SCOPE int	TclUtfCasecmp(const char *cs, const char *ct);
  3280   3291   MODULE_SCOPE size_t	TclUtfCount(int ch);
  3281   3292   MODULE_SCOPE Tcl_Obj *	TclpNativeToNormalized(void *clientData);
  3282   3293   MODULE_SCOPE Tcl_Obj *	TclpFilesystemPathType(Tcl_Obj *pathPtr);
  3283   3294   MODULE_SCOPE int	TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
  3284   3295   			    Tcl_LoadHandle *loadHandle,
................................................................................
  4500   4511      }
  4501   4512   #else
  4502   4513   #define TclGetStringFromObj(objPtr, lenPtr) \
  4503   4514       (((objPtr)->bytes \
  4504   4515   	    ? NULL : Tcl_GetString((objPtr)), \
  4505   4516   	    *(lenPtr) = (objPtr)->length, (objPtr)->bytes))
  4506   4517   #define TclGetUnicodeFromObj(objPtr, lenPtr) \
  4507         -    (Tcl_GetUnicodeFromObj(objPtr, NULL), \
         4518  +    (Tcl_GetUnicodeFromObj((objPtr), NULL), \
  4508   4519   	    *(lenPtr) = *((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1), \
  4509         -	    Tcl_GetUnicodeFromObj(objPtr, NULL))
         4520  +	    Tcl_GetUnicodeFromObj((objPtr), NULL))
  4510   4521   #define TclGetByteArrayFromObj(objPtr, lenPtr) \
  4511         -    (Tcl_GetByteArrayFromObj(objPtr, NULL) ? \
         4522  +    (Tcl_GetByteArrayFromObj((objPtr), NULL) ? \
  4512   4523   	(*(lenPtr) = *((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1), \
  4513         -	(unsigned char *)(((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1) + 2)) : (*(lenPtr) = 0, NULL))
         4524  +	(unsigned char *)(((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1) + 2)) : NULL)
  4514   4525   #endif
  4515   4526   
  4516   4527   /*
  4517   4528    *----------------------------------------------------------------
  4518   4529    * Macro used by the Tcl core to clean out an object's internal
  4519   4530    * representation. Does not actually reset the rep's bytes. The ANSI C
  4520   4531    * "prototype" for this macro is:

Changes to generic/tclMain.c.

    55     55   
    56     56   /*
    57     57    * Further on, in UNICODE mode we just use Tcl_NewUnicodeObj, otherwise
    58     58    * NewNativeObj is needed (which provides proper conversion from native
    59     59    * encoding to UTF-8).
    60     60    */
    61     61   
    62         -#ifdef UNICODE
           62  +#if defined(UNICODE) && (TCL_UTF_MAX <= 4)
    63     63   #   define NewNativeObj Tcl_NewUnicodeObj
    64         -#else /* !UNICODE */
           64  +#else /* !UNICODE || (TCL_UTF_MAX > 4) */
    65     65   static inline Tcl_Obj *
    66     66   NewNativeObj(
    67         -    char *string,
           67  +    TCHAR *string,
    68     68       size_t length)
    69     69   {
    70     70       Tcl_DString ds;
    71     71   
    72         -    Tcl_ExternalToUtfDString(NULL, string, length, &ds);
           72  +#ifdef UNICODE
           73  +    if (length > 0) {
           74  +	length *= sizeof(WCHAR);
           75  +    }
           76  +    Tcl_WinTCharToUtf(string, length, &ds);
           77  +#else
           78  +    Tcl_ExternalToUtfDString(NULL, (char *) string, length, &ds);
           79  +#endif
    73     80       return TclDStringToObj(&ds);
    74     81   }
    75         -#endif /* !UNICODE */
           82  +#endif /* !UNICODE || (TCL_UTF_MAX > 4) */
    76     83   
    77     84   /*
    78     85    * Declarations for various library functions and variables (don't want to
    79     86    * include tclPort.h here, because people might copy this file out of the Tcl
    80     87    * source directory to make their own modified versions).
    81     88    */
    82     89   

Changes to generic/tclOOBasic.c.

   601    601   	}
   602    602   	Tcl_AppendToObj(errorMsg, methodNames[i], -1);
   603    603       }
   604    604       if (i) {
   605    605   	Tcl_AppendToObj(errorMsg, " or ", -1);
   606    606       }
   607    607       Tcl_AppendToObj(errorMsg, methodNames[i], -1);
   608         -    Tcl_Free(methodNames);
          608  +    Tcl_Free((void *)methodNames);
   609    609       Tcl_SetObjResult(interp, errorMsg);
   610    610       Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
   611    611   	    TclGetString(objv[skip]), NULL);
   612    612       return TCL_ERROR;
   613    613   }
   614    614   
   615    615   /*

Changes to generic/tclOOCall.c.

   631    631   
   632    632       if (i > 0) {
   633    633   	if (i > 1) {
   634    634   	    qsort((void *) strings, i, sizeof(char *), CmpStr);
   635    635   	}
   636    636   	*stringsPtr = strings;
   637    637       } else {
   638         -	Tcl_Free(strings);
          638  +	Tcl_Free((void *)strings);
   639    639   	*stringsPtr = NULL;
   640    640       }
   641    641       return i;
   642    642   }
   643    643   
   644    644   /* Comparator for SortMethodNames */
   645    645   static int

Changes to generic/tclOOInfo.c.

   608    608   		&names);
   609    609   
   610    610   	for (i=0 ; i<numNames ; i++) {
   611    611   	    Tcl_ListObjAppendElement(NULL, resultObj,
   612    612   		    Tcl_NewStringObj(names[i], -1));
   613    613   	}
   614    614   	if (numNames > 0) {
   615         -	    Tcl_Free(names);
          615  +	    Tcl_Free((void *)names);
   616    616   	}
   617    617       } else if (oPtr->methodsPtr) {
   618    618   	FOREACH_HASH(namePtr, mPtr, oPtr->methodsPtr) {
   619    619   	    if (mPtr->typePtr && (mPtr->flags & SCOPE_FLAGS) == flag) {
   620    620   		Tcl_ListObjAppendElement(NULL, resultObj, namePtr);
   621    621   	    }
   622    622   	}
................................................................................
  1362   1362   	int i, numNames = TclOOGetSortedClassMethodList(clsPtr, flag, &names);
  1363   1363   
  1364   1364   	for (i=0 ; i<numNames ; i++) {
  1365   1365   	    Tcl_ListObjAppendElement(NULL, resultObj,
  1366   1366   		    Tcl_NewStringObj(names[i], -1));
  1367   1367   	}
  1368   1368   	if (numNames > 0) {
  1369         -	    Tcl_Free(names);
         1369  +	    Tcl_Free((void *)names);
  1370   1370   	}
  1371   1371       } else {
  1372   1372   	FOREACH_HASH_DECLS;
  1373   1373   
  1374   1374   	FOREACH_HASH(namePtr, mPtr, &clsPtr->classMethods) {
  1375   1375   	    if (mPtr->typePtr && (mPtr->flags & SCOPE_FLAGS) == flag) {
  1376   1376   		Tcl_ListObjAppendElement(NULL, resultObj, namePtr);

Changes to generic/tclRegexp.c.

   260    260   				 * in (sub-)range here. */
   261    261   {
   262    262       TclRegexp *regexpPtr = (TclRegexp *) re;
   263    263       const char *string;
   264    264   
   265    265       if (index > regexpPtr->re.re_nsub) {
   266    266   	*startPtr = *endPtr = NULL;
   267         -    } else if (regexpPtr->matches[index].rm_so == (size_t)-1) {
          267  +    } else if (regexpPtr->matches[index].rm_so == -1) {
   268    268   	*startPtr = *endPtr = NULL;
   269    269       } else {
   270    270   	if (regexpPtr->objPtr) {
   271    271   	    string = TclGetString(regexpPtr->objPtr);
   272    272   	} else {
   273    273   	    string = regexpPtr->string;
   274    274   	}

Changes to generic/tclStrToD.c.

  4517   4517   	if (lsb == -1-shift) {
  4518   4518   
  4519   4519   	    /*
  4520   4520   	     * Round to even
  4521   4521   	     */
  4522   4522   
  4523   4523   	    mp_div_2d(a, -shift, &b, NULL);
  4524         -	    if (mp_isodd(&b)) {
         4524  +	    if (mp_get_bit(&b, 0)) {
  4525   4525   		if (b.sign == MP_ZPOS) {
  4526   4526   		    mp_add_d(&b, 1, &b);
  4527   4527   		} else {
  4528   4528   		    mp_sub_d(&b, 1, &b);
  4529   4529   		}
  4530   4530   	    }
  4531   4531   	} else {

Changes to generic/tclStringObj.c.

   393    393   
   394    394   size_t
   395    395   Tcl_GetCharLength(
   396    396       Tcl_Obj *objPtr)		/* The String object to get the num chars
   397    397   				 * of. */
   398    398   {
   399    399       String *stringPtr;
   400         -    size_t numChars;
          400  +    size_t numChars = 0;
   401    401   
   402    402       /*
   403    403        * Quick, no-shimmer return for short string reps.
   404    404        */
   405    405   
   406    406       if ((objPtr->bytes) && (objPtr->length < 2)) {
   407    407   	/* 0 bytes -> 0 chars; 1 byte -> 1 char */
................................................................................
   514    514   
   515    515       /*
   516    516        * Optimize the case where we're really dealing with a bytearray object
   517    517        * we don't need to convert to a string to perform the indexing operation.
   518    518        */
   519    519   
   520    520       if (TclIsPureByteArray(objPtr)) {
   521         -	size_t length;
          521  +	size_t length = 0;
   522    522   	unsigned char *bytes = TclGetByteArrayFromObj(objPtr, &length);
   523    523   	if (index >= length) {
   524    524   		return -1;
   525    525   	}
   526    526   
   527    527   	return bytes[index];
   528    528       }
................................................................................
   638    638   Tcl_GetRange(
   639    639       Tcl_Obj *objPtr,		/* The Tcl object to find the range of. */
   640    640       size_t first,			/* First index of the range. */
   641    641       size_t last)			/* Last index of the range. */
   642    642   {
   643    643       Tcl_Obj *newObjPtr;		/* The Tcl object to find the range of. */
   644    644       String *stringPtr;
   645         -    size_t length;
          645  +    size_t length = 0;
   646    646   
   647    647       if (first == TCL_INDEX_NONE) {
   648    648   	first = TCL_INDEX_START;
   649    649       }
   650    650       if (last + 2 <= first + 1) {
   651    651   	return Tcl_NewObj();
   652    652       }
................................................................................
  1234   1234   
  1235   1235   void
  1236   1236   Tcl_AppendObjToObj(
  1237   1237       Tcl_Obj *objPtr,		/* Points to the object to append to. */
  1238   1238       Tcl_Obj *appendObjPtr)	/* Object to append. */
  1239   1239   {
  1240   1240       String *stringPtr;
  1241         -    size_t length, numChars;
         1241  +    size_t length = 0, numChars;
  1242   1242       size_t appendNumChars = TCL_AUTO_LENGTH;
  1243   1243       const char *bytes;
  1244   1244   
  1245   1245       /*
  1246   1246        * Special case: second object is standard-empty is fast case. We know
  1247   1247        * that appending nothing to anything leaves that starting anything...
  1248   1248        */
................................................................................
  1275   1275   	 * Write!). For the sake of extensions that go off into that realm,
  1276   1276   	 * though, here's a more complex approach that can handle all the
  1277   1277   	 * cases.
  1278   1278   	 *
  1279   1279   	 * First, get the lengths.
  1280   1280   	 */
  1281   1281   
  1282         -	size_t lengthSrc;
         1282  +	size_t lengthSrc = 0;
  1283   1283   
  1284   1284   	(void) TclGetByteArrayFromObj(objPtr, &length);
  1285   1285   	(void) TclGetByteArrayFromObj(appendObjPtr, &lengthSrc);
  1286   1286   
  1287   1287   	/*
  1288   1288   	 * Grow buffer enough for the append.
  1289   1289   	 */
................................................................................
  1940   1940   		    numChars = precision;
  1941   1941   		    Tcl_IncrRefCount(segment);
  1942   1942   		    allocSegment = 1;
  1943   1943   		}
  1944   1944   	    }
  1945   1945   	    break;
  1946   1946   	case 'c': {
  1947         -	    char buf[4];
         1947  +	    char buf[TCL_UTF_MAX] = "";
  1948   1948   	    int code, length;
  1949   1949   
  1950   1950   	    if (TclGetIntFromObj(interp, segment, &code) != TCL_OK) {
  1951   1951   		goto error;
  1952   1952   	    }
  1953   1953   	    length = Tcl_UniCharToUtf(code, buf);
  1954   1954   	    if ((code >= 0xD800) && (length < 3)) {
................................................................................
  2945   2945       } while (--oc && (binary || allowUniChar));
  2946   2946   
  2947   2947       if (binary) {
  2948   2948   	/*
  2949   2949   	 * Result will be pure byte array. Pre-size it
  2950   2950   	 */
  2951   2951   
  2952         -	size_t numBytes;
         2952  +	size_t numBytes = 0;
  2953   2953   	ov = objv;
  2954   2954   	oc = objc;
  2955   2955   	do {
  2956   2956   	    Tcl_Obj *objPtr = *ov++;
  2957   2957   
  2958   2958   	    /*
  2959   2959   	     * Every argument is either a bytearray with a ("pure")
................................................................................
  3096   3096   
  3097   3097   	/*
  3098   3098   	 * Broken interface! Byte array value routines offer no way to handle
  3099   3099   	 * failure to allocate enough space. Following stanza may panic.
  3100   3100   	 */
  3101   3101   
  3102   3102   	if (inPlace && !Tcl_IsShared(*objv)) {
  3103         -	    size_t start;
         3103  +	    size_t start = 0;
  3104   3104   
  3105   3105   	    objResultPtr = *objv++; objc--;
  3106   3106   	    (void)TclGetByteArrayFromObj(objResultPtr, &start);
  3107   3107   	    dst = Tcl_SetByteArrayLength(objResultPtr, length) + start;
  3108   3108   	} else {
  3109   3109   	    objResultPtr = Tcl_NewByteArrayObj(NULL, length);
  3110   3110   	    dst = Tcl_SetByteArrayLength(objResultPtr, length);
................................................................................
  3115   3115   	    /*
  3116   3116   	     * Every argument is either a bytearray with a ("pure")
  3117   3117   	     * value we know we can safely use, or it is an empty string.
  3118   3118   	     * We don't need to copy bytes from the empty strings.
  3119   3119   	     */
  3120   3120   
  3121   3121   	    if (TclIsPureByteArray(objPtr)) {
  3122         -		size_t more;
         3122  +		size_t more = 0;
  3123   3123   		unsigned char *src = TclGetByteArrayFromObj(objPtr, &more);
  3124   3124   		memcpy(dst, src, more);
  3125   3125   		dst += more;
  3126   3126   	    }
  3127   3127   	}
  3128   3128       } else if (allowUniChar && requestUniChar) {
  3129   3129   	/* Efficiently produce a pure Tcl_UniChar array result */
................................................................................
  3260   3260       Tcl_Obj *value2Ptr,
  3261   3261       int checkEq,		/* comparison is only for equality */
  3262   3262       int nocase,			/* comparison is not case sensitive */
  3263   3263       size_t reqlength)		/* requested length */
  3264   3264   {
  3265   3265       char *s1, *s2;
  3266   3266       int empty, match;
  3267         -    size_t length, s1len, s2len;
         3267  +    size_t length, s1len = 0, s2len = 0;
  3268   3268       memCmpFn_t memCmpFn;
  3269   3269   
  3270   3270       if ((reqlength == 0) || (value1Ptr == value2Ptr)) {
  3271   3271   	/*
  3272   3272   	 * Always match at 0 chars of if it is the same obj.
  3273   3273   	 */
  3274   3274   	match = 0;
................................................................................
  3441   3441   
  3442   3442   size_t
  3443   3443   TclStringFirst(
  3444   3444       Tcl_Obj *needle,
  3445   3445       Tcl_Obj *haystack,
  3446   3446       size_t start)
  3447   3447   {
  3448         -    size_t lh, ln = Tcl_GetCharLength(needle);
         3448  +    size_t lh = 0, ln = Tcl_GetCharLength(needle);
  3449   3449   
  3450   3450       if (start == TCL_AUTO_LENGTH) {
  3451   3451   	start = 0;
  3452   3452       }
  3453   3453       if (ln == 0) {
  3454   3454   	/* We don't find empty substrings.  Bizarre!
  3455   3455   	 * Whenever this routine is turned into a proper substring
................................................................................
  3545   3545   
  3546   3546   size_t
  3547   3547   TclStringLast(
  3548   3548       Tcl_Obj *needle,
  3549   3549       Tcl_Obj *haystack,
  3550   3550       size_t last)
  3551   3551   {
  3552         -    size_t lh, ln = Tcl_GetCharLength(needle);
         3552  +    size_t lh = 0, ln = Tcl_GetCharLength(needle);
  3553   3553   
  3554   3554       if (ln == 0) {
  3555   3555   	/*
  3556   3556   	 * 	We don't find empty substrings.  Bizarre!
  3557   3557   	 *
  3558   3558   	 * 	TODO: When we one day make this a true substring
  3559   3559   	 * 	finder, change this to "return last", after limitation.
................................................................................
  3655   3655       int flags)
  3656   3656   {
  3657   3657       String *stringPtr;
  3658   3658       Tcl_UniChar ch = 0;
  3659   3659       int inPlace = flags & TCL_STRING_IN_PLACE;
  3660   3660   
  3661   3661       if (TclIsPureByteArray(objPtr)) {
  3662         -	size_t numBytes;
         3662  +	size_t numBytes = 0;
  3663   3663   	unsigned char *from = TclGetByteArrayFromObj(objPtr, &numBytes);
  3664   3664   
  3665   3665   	if (!inPlace || Tcl_IsShared(objPtr)) {
  3666   3666   	    objPtr = Tcl_NewByteArrayObj(NULL, numBytes);
  3667   3667   	}
  3668   3668   	ReverseBytes(Tcl_GetByteArrayFromObj(objPtr, NULL), from, numBytes);
  3669   3669   	return objPtr;
................................................................................
  3804   3804        * The caller very likely had to call Tcl_GetCharLength() or similar
  3805   3805        * to be able to process index values.  This means it is like that
  3806   3806        * objPtr is either a proper "bytearray" or a "string" or else it has
  3807   3807        * a known and short string rep.
  3808   3808        */
  3809   3809   
  3810   3810       if (TclIsPureByteArray(objPtr)) {
  3811         -	size_t numBytes;
         3811  +	size_t numBytes = 0;
  3812   3812   	unsigned char *bytes = TclGetByteArrayFromObj(objPtr, &numBytes);
  3813   3813   
  3814   3814   	if (insertPtr == NULL) {
  3815   3815   	    /* Replace something with nothing. */
  3816   3816   
  3817   3817   	    assert ( first <= numBytes ) ;
  3818   3818   	    assert ( count <= numBytes ) ;
................................................................................
  3827   3827   
  3828   3828   	/* Replace everything */
  3829   3829   	if ((first == 0) && (count == numBytes)) {
  3830   3830   	    return insertPtr;
  3831   3831   	}
  3832   3832   
  3833   3833   	if (TclIsPureByteArray(insertPtr)) {
  3834         -	    size_t newBytes;
         3834  +	    size_t newBytes = 0;
  3835   3835   	    unsigned char *iBytes
  3836   3836   		    = TclGetByteArrayFromObj(insertPtr, &newBytes);
  3837   3837   
  3838   3838   	    if (count == newBytes && inPlace && !Tcl_IsShared(objPtr)) {
  3839   3839   		/*
  3840   3840   		 * Removal count and replacement count are equal.
  3841   3841   		 * Other conditions permit. Do in-place splice.

Changes to generic/tclStubInit.c.

    47     47   #undef Tcl_FindExecutable
    48     48   #undef Tcl_SetExitProc
    49     49   #undef Tcl_SetPanicProc
    50     50   #undef TclpGetPid
    51     51   #undef TclSockMinimumBuffers
    52     52   #undef Tcl_SetIntObj
    53     53   #undef TclStaticPackage
           54  +#undef Tcl_BackgroundError
    54     55   #define TclStaticPackage Tcl_StaticPackage
    55     56   
    56     57   #ifdef TCL_MEM_DEBUG
    57     58   #   define Tcl_Alloc TclpAlloc
    58     59   #   define Tcl_Free TclpFree
    59     60   #   define Tcl_Realloc TclpRealloc
    60     61   #   undef Tcl_AttemptAlloc
................................................................................
   113    114   
   114    115   char *
   115    116   Tcl_WinUtfToTChar(
   116    117       const char *string,
   117    118       size_t len,
   118    119       Tcl_DString *dsPtr)
   119    120   {
   120         -#if TCL_UTF_MAX > 4
   121         -    Tcl_UniChar ch = 0;
   122         -    wchar_t *w, *wString;
   123         -    const char *p, *end;
   124         -    int oldLength;
   125         -#endif
   126         -
   127    121       Tcl_DStringInit(dsPtr);
   128    122       if (!string) {
   129    123   	return NULL;
   130    124       }
   131         -#if TCL_UTF_MAX > 4
   132         -
   133         -    if (len < 0) {
   134         -	len = strlen(string);
   135         -    }
   136         -
   137         -    /*
   138         -     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
   139         -     * bytes.
   140         -     */
   141         -
   142         -    oldLength = Tcl_DStringLength(dsPtr);
   143         -
   144         -    Tcl_DStringSetLength(dsPtr,
   145         -	    oldLength + (int) ((len + 1) * sizeof(wchar_t)));
   146         -    wString = (wchar_t *) (Tcl_DStringValue(dsPtr) + oldLength);
   147         -
   148         -    w = wString;
   149         -    p = string;
   150         -    end = string + len - 4;
   151         -    while (p < end) {
   152         -	p += TclUtfToUniChar(p, &ch);
   153         -	if (ch > 0xFFFF) {
   154         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   155         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   156         -	} else {
   157         -	    *w++ = ch;
   158         -	}
   159         -    }
   160         -    end += 4;
   161         -    while (p < end) {
   162         -	if (Tcl_UtfCharComplete(p, end-p)) {
   163         -	    p += TclUtfToUniChar(p, &ch);
   164         -	} else {
   165         -	    ch = UCHAR(*p++);
   166         -	}
   167         -	if (ch > 0xFFFF) {
   168         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   169         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   170         -	} else {
   171         -	    *w++ = ch;
   172         -	}
   173         -    }
   174         -    *w = '\0';
   175         -    Tcl_DStringSetLength(dsPtr,
   176         -	    oldLength + ((char *) w - (char *) wString));
   177         -
   178         -    return (char *)wString;
   179         -#else
   180         -    return (char *)Tcl_UtfToUniCharDString(string, len, dsPtr);
   181         -#endif
          125  +    return (char *)TclUtfToWCharDString(string, len, dsPtr);
   182    126   }
   183    127   
   184    128   char *
   185    129   Tcl_WinTCharToUtf(
   186    130       const char *string,
   187    131       size_t len,
   188    132       Tcl_DString *dsPtr)
   189    133   {
   190         -#if TCL_UTF_MAX > 4
   191         -    const wchar_t *w, *wEnd;
   192         -    char *p, *result;
   193         -    int oldLength, blen = 1;
   194         -#endif
   195         -
   196    134       Tcl_DStringInit(dsPtr);
   197    135       if (!string) {
   198    136   	return NULL;
   199    137       }
   200    138       if (len == TCL_AUTO_LENGTH) {
   201    139   	len = wcslen((wchar_t *)string);
   202    140       } else {
   203    141   	len /= 2;
   204    142       }
   205         -#if TCL_UTF_MAX > 4
   206         -    oldLength = Tcl_DStringLength(dsPtr);
   207         -    Tcl_DStringSetLength(dsPtr, oldLength + (len + 1) * 4);
   208         -    result = Tcl_DStringValue(dsPtr) + oldLength;
   209         -
   210         -    p = result;
   211         -    wEnd = (wchar_t *)string + len;
   212         -    for (w = (wchar_t *)string; w < wEnd; ) {
   213         -	if (!blen && ((*w & 0xFC00) != 0xDC00)) {
   214         -	    /* Special case for handling high surrogates. */
   215         -	    p += Tcl_UniCharToUtf(-1, p);
   216         -	}
   217         -	blen = Tcl_UniCharToUtf(*w, p);
   218         -	p += blen;
   219         -	if ((*w >= 0xD800) && (blen < 3)) {
   220         -	    /* Indication that high surrogate is handled */
   221         -	    blen = 0;
   222         -	}
   223         -	w++;
   224         -    }
   225         -    if (!blen) {
   226         -	/* Special case for handling high surrogates. */
   227         -	p += Tcl_UniCharToUtf(-1, p);
   228         -    }
   229         -    Tcl_DStringSetLength(dsPtr, oldLength + (p - result));
   230         -
   231         -    return result;
   232         -#else
   233         -    return Tcl_UniCharToUtfDString((Tcl_UniChar *)string, len, dsPtr);
   234         -#endif
          143  +    return TclWCharToUtfDString((const WCHAR *)string, len, dsPtr);
   235    144   }
   236    145   
   237    146   #if defined(TCL_WIDE_INT_IS_LONG)
   238    147   /* On Cygwin64, long is 64-bit while on Win64 long is 32-bit. Therefore
   239    148    * we have to make sure that all stub entries on Cygwin64 follow the Win64
   240    149    * signature. Tcl 9 must find a better solution, but that cannot be done
   241    150    * without introducing a binary incompatibility.
................................................................................
   725    634       TclBN_mp_sub_d, /* 43 */
   726    635       TclBN_mp_to_unsigned_bin, /* 44 */
   727    636       TclBN_mp_to_unsigned_bin_n, /* 45 */
   728    637       TclBN_mp_toradix_n, /* 46 */
   729    638       TclBN_mp_unsigned_bin_size, /* 47 */
   730    639       TclBN_mp_xor, /* 48 */
   731    640       TclBN_mp_zero, /* 49 */
   732         -    TclBN_reverse, /* 50 */
   733         -    TclBN_fast_s_mp_mul_digs, /* 51 */
   734         -    TclBN_fast_s_mp_sqr, /* 52 */
   735         -    TclBN_mp_karatsuba_mul, /* 53 */
   736         -    TclBN_mp_karatsuba_sqr, /* 54 */
   737         -    TclBN_mp_toom_mul, /* 55 */
   738         -    TclBN_mp_toom_sqr, /* 56 */
   739         -    TclBN_s_mp_add, /* 57 */
   740         -    TclBN_s_mp_mul_digs, /* 58 */
   741         -    TclBN_s_mp_sqr, /* 59 */
   742         -    TclBN_s_mp_sub, /* 60 */
          641  +    0, /* 50 */
          642  +    0, /* 51 */
          643  +    0, /* 52 */
          644  +    0, /* 53 */
          645  +    0, /* 54 */
          646  +    0, /* 55 */
          647  +    0, /* 56 */
          648  +    0, /* 57 */
          649  +    0, /* 58 */
          650  +    0, /* 59 */
          651  +    0, /* 60 */
   743    652       TclBN_mp_init_set_int, /* 61 */
   744    653       TclBN_mp_set_int, /* 62 */
   745    654       TclBN_mp_cnt_lsb, /* 63 */
   746    655       0, /* 64 */
   747    656       0, /* 65 */
   748    657       0, /* 66 */
   749    658       TclBN_mp_expt_d_ex, /* 67 */
................................................................................
   752    661       TclBN_mp_set_long, /* 70 */
   753    662       TclBN_mp_get_long, /* 71 */
   754    663       TclBN_mp_get_int, /* 72 */
   755    664       TclBN_mp_tc_and, /* 73 */
   756    665       TclBN_mp_tc_or, /* 74 */
   757    666       TclBN_mp_tc_xor, /* 75 */
   758    667       TclBN_mp_tc_div_2d, /* 76 */
          668  +    TclBN_mp_get_bit, /* 77 */
   759    669   };
   760    670   
   761    671   static const TclStubHooks tclStubHooks = {
   762    672       &tclPlatStubs,
   763    673       &tclIntStubs,
   764    674       &tclIntPlatStubs
   765    675   };

Changes to generic/tclTestObj.c.

   286    286   	    return TCL_ERROR;
   287    287   	}
   288    288   	if (Tcl_GetBignumFromObj(interp, varPtr[varIndex],
   289    289   		&bignumValue) != TCL_OK) {
   290    290   	    return TCL_ERROR;
   291    291   	}
   292    292   	if (!Tcl_IsShared(varPtr[varIndex])) {
   293         -	    Tcl_SetIntObj(varPtr[varIndex], mp_iseven(&bignumValue));
          293  +	    Tcl_SetIntObj(varPtr[varIndex], !mp_get_bit(&bignumValue, 0));
   294    294   	} else {
   295         -	    SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(mp_iseven(&bignumValue)));
          295  +	    SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_get_bit(&bignumValue, 0)));
   296    296   	}
   297    297   	mp_clear(&bignumValue);
   298    298   	break;
   299    299   
   300    300       case BIGNUM_RADIXSIZE:
   301    301   	if (objc != 3) {
   302    302   	    Tcl_WrongNumArgs(interp, 2, objv, "varIndex");
................................................................................
   621    621   	argv[i-4] = Tcl_GetString(objv[i]);
   622    622       }
   623    623       argv[objc-4] = NULL;
   624    624   
   625    625       result = Tcl_GetIndexFromObj((setError? interp : NULL), objv[3],
   626    626   	    argv, "token", INDEX_TEMP_TABLE|(allowAbbrev? 0 : TCL_EXACT),
   627    627   	    &index);
   628         -    Tcl_Free(argv);
          628  +    Tcl_Free((void *)argv);
   629    629       if (result == TCL_OK) {
   630    630   	Tcl_SetIntObj(Tcl_GetObjResult(interp), index);
   631    631       }
   632    632       return result;
   633    633   }
   634    634   
   635    635   /*

Changes to generic/tclThreadAlloc.c.

  1078   1078   {
  1079   1079       unsigned int i;
  1080   1080   
  1081   1081       listLockPtr = TclpNewAllocMutex();
  1082   1082       objLockPtr = TclpNewAllocMutex();
  1083   1083       for (i = 0; i < NBUCKETS; ++i) {
  1084   1084   	bucketInfo[i].blockSize = MINALLOC << i;
  1085         -	bucketInfo[i].maxBlocks = 1 << (NBUCKETS - 1 - i);
         1085  +	bucketInfo[i].maxBlocks = ((size_t)1) << (NBUCKETS - 1 - i);
  1086   1086   	bucketInfo[i].numMove = i < NBUCKETS - 1 ?
  1087   1087   		1 << (NBUCKETS - 2 - i) : 1;
  1088   1088   	bucketInfo[i].lockPtr = TclpNewAllocMutex();
  1089   1089       }
  1090   1090       TclpInitAllocCache();
  1091   1091   }
  1092   1092   

Changes to generic/tclTomMath.decls.

   170    170   }
   171    171   declare 48 {
   172    172       int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
   173    173   }
   174    174   declare 49 {
   175    175       void TclBN_mp_zero(mp_int *a)
   176    176   }
   177         -
   178         -# internal routines to libtommath - should not be called but must be
   179         -# exported to accommodate the "tommath" extension
   180         -
   181         -declare 50 {
   182         -    void TclBN_reverse(unsigned char *s, int len)
   183         -}
   184         -declare 51 {
   185         -    int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
   186         -}
   187         -declare 52 {
   188         -    int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
   189         -}
   190         -declare 53 {
   191         -    int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
   192         -}
   193         -declare 54 {
   194         -    int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
   195         -}
   196         -declare 55 {
   197         -    int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
   198         -}
   199         -declare 56 {
   200         -    int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
   201         -}
   202         -declare 57 {
   203         -    int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
   204         -}
   205         -declare 58 {
   206         -    int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
   207         -}
   208         -declare 59 {
   209         -    int TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
   210         -}
   211         -declare 60 {
   212         -    int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
   213         -}
   214    177   declare 61 {
   215    178       int TclBN_mp_init_set_int(mp_int *a, unsigned long i)
   216    179   }
   217    180   declare 62 {
   218    181       int TclBN_mp_set_int(mp_int *a, unsigned long i)
   219    182   }
   220    183   declare 63 {
................................................................................
   266    229   }
   267    230   declare 75 {
   268    231       int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
   269    232   }
   270    233   declare 76 {
   271    234       int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
   272    235   }
          236  +declare 77 {
          237  +    int TclBN_mp_get_bit(const mp_int *a, int b)
          238  +}
   273    239   
   274    240   
   275    241   # Local Variables:
   276    242   # mode: tcl
   277    243   # End:

Changes to generic/tclTomMathDecls.h.

    70     70   #define mp_div_2 TclBN_mp_div_2
    71     71   #define mp_div_2d TclBN_mp_div_2d
    72     72   #define mp_div_3 TclBN_mp_div_3
    73     73   #define mp_div_d TclBN_mp_div_d
    74     74   #define mp_exch TclBN_mp_exch
    75     75   #define mp_expt_d TclBN_mp_expt_d
    76     76   #define mp_expt_d_ex TclBN_mp_expt_d_ex
           77  +#define mp_get_bit TclBN_mp_get_bit
    77     78   #define mp_get_int TclBN_mp_get_int
    78     79   #define mp_get_long TclBN_mp_get_long
    79     80   #define mp_get_long_long TclBN_mp_get_long_long
    80     81   #define mp_grow TclBN_mp_grow
    81     82   #define mp_init TclBN_mp_init
    82     83   #define mp_init_copy TclBN_mp_init_copy
    83     84   #define mp_init_multi TclBN_mp_init_multi
................................................................................
   119    120   #define mp_unsigned_bin_size TclBN_mp_unsigned_bin_size
   120    121   #define mp_xor TclBN_mp_xor
   121    122   #define mp_zero TclBN_mp_zero
   122    123   #define s_mp_add TclBN_s_mp_add
   123    124   #define s_mp_mul_digs TclBN_s_mp_mul_digs
   124    125   #define s_mp_sqr TclBN_s_mp_sqr
   125    126   #define s_mp_sub TclBN_s_mp_sub
          127  +
          128  +MODULE_SCOPE void TclBN_reverse(unsigned char *s, int len);
          129  +MODULE_SCOPE int TclBN_fast_s_mp_mul_digs(const mp_int *a,
          130  +				const mp_int *b, mp_int *c, int digs);
          131  +MODULE_SCOPE int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
          132  +MODULE_SCOPE int TclBN_mp_karatsuba_mul(const mp_int *a,
          133  +				const mp_int *b, mp_int *c);
          134  +MODULE_SCOPE int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
          135  +MODULE_SCOPE int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
          136  +				mp_int *c);
          137  +MODULE_SCOPE int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
          138  +MODULE_SCOPE int TclBN_s_mp_add(const mp_int *a, const mp_int *b,
          139  +				mp_int *c);
          140  +MODULE_SCOPE int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
          141  +				mp_int *c, int digs);
          142  +MODULE_SCOPE int TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
          143  +MODULE_SCOPE int TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
          144  +				mp_int *c);
   126    145   
   127    146   #undef TCL_STORAGE_CLASS
   128    147   #ifdef BUILD_tcl
   129    148   #   define TCL_STORAGE_CLASS DLLEXPORT
   130    149   #else
   131    150   #   ifdef USE_TCL_STUBS
   132    151   #      define TCL_STORAGE_CLASS
................................................................................
   267    286   /* 47 */
   268    287   EXTERN int		TclBN_mp_unsigned_bin_size(const mp_int *a);
   269    288   /* 48 */
   270    289   EXTERN int		TclBN_mp_xor(const mp_int *a, const mp_int *b,
   271    290   				mp_int *c);
   272    291   /* 49 */
   273    292   EXTERN void		TclBN_mp_zero(mp_int *a);
   274         -/* 50 */
   275         -EXTERN void		TclBN_reverse(unsigned char *s, int len);
   276         -/* 51 */
   277         -EXTERN int		TclBN_fast_s_mp_mul_digs(const mp_int *a,
   278         -				const mp_int *b, mp_int *c, int digs);
   279         -/* 52 */
   280         -EXTERN int		TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
   281         -/* 53 */
   282         -EXTERN int		TclBN_mp_karatsuba_mul(const mp_int *a,
   283         -				const mp_int *b, mp_int *c);
   284         -/* 54 */
   285         -EXTERN int		TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
   286         -/* 55 */
   287         -EXTERN int		TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
   288         -				mp_int *c);
   289         -/* 56 */
   290         -EXTERN int		TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
   291         -/* 57 */
   292         -EXTERN int		TclBN_s_mp_add(const mp_int *a, const mp_int *b,
   293         -				mp_int *c);
   294         -/* 58 */
   295         -EXTERN int		TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
   296         -				mp_int *c, int digs);
   297         -/* 59 */
   298         -EXTERN int		TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
   299         -/* 60 */
   300         -EXTERN int		TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
   301         -				mp_int *c);
          293  +/* Slot 50 is reserved */
          294  +/* Slot 51 is reserved */
          295  +/* Slot 52 is reserved */
          296  +/* Slot 53 is reserved */
          297  +/* Slot 54 is reserved */
          298  +/* Slot 55 is reserved */
          299  +/* Slot 56 is reserved */
          300  +/* Slot 57 is reserved */
          301  +/* Slot 58 is reserved */
          302  +/* Slot 59 is reserved */
          303  +/* Slot 60 is reserved */
   302    304   /* 61 */
   303    305   EXTERN int		TclBN_mp_init_set_int(mp_int *a, unsigned long i);
   304    306   /* 62 */
   305    307   EXTERN int		TclBN_mp_set_int(mp_int *a, unsigned long i);
   306    308   /* 63 */
   307    309   EXTERN int		TclBN_mp_cnt_lsb(const mp_int *a);
   308    310   /* Slot 64 is reserved */
................................................................................
   328    330   EXTERN int		TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
   329    331   				mp_int *c);
   330    332   /* 75 */
   331    333   EXTERN int		TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
   332    334   				mp_int *c);
   333    335   /* 76 */
   334    336   EXTERN int		TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c);
          337  +/* 77 */
          338  +EXTERN int		TclBN_mp_get_bit(const mp_int *a, int b);
   335    339   
   336    340   typedef struct TclTomMathStubs {
   337    341       int magic;
   338    342       void *hooks;
   339    343   
   340    344       int (*tclBN_epoch) (void); /* 0 */
   341    345       int (*tclBN_revision) (void); /* 1 */
................................................................................
   383    387       int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
   384    388       int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
   385    389       int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
   386    390       int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
   387    391       int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
   388    392       int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
   389    393       void (*tclBN_mp_zero) (mp_int *a); /* 49 */
   390         -    void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
   391         -    int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
   392         -    int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
   393         -    int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
   394         -    int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
   395         -    int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
   396         -    int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
   397         -    int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
   398         -    int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
   399         -    int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
   400         -    int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
          394  +    void (*reserved50)(void);
          395  +    void (*reserved51)(void);
          396  +    void (*reserved52)(void);
          397  +    void (*reserved53)(void);
          398  +    void (*reserved54)(void);
          399  +    void (*reserved55)(void);
          400  +    void (*reserved56)(void);
          401  +    void (*reserved57)(void);
          402  +    void (*reserved58)(void);
          403  +    void (*reserved59)(void);
          404  +    void (*reserved60)(void);
   401    405       int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
   402    406       int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
   403    407       int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
   404    408       void (*reserved64)(void);
   405    409       void (*reserved65)(void);
   406    410       void (*reserved66)(void);
   407    411       int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
................................................................................
   410    414       int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
   411    415       unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */
   412    416       unsigned long (*tclBN_mp_get_int) (const mp_int *a); /* 72 */
   413    417       int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
   414    418       int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
   415    419       int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
   416    420       int (*tclBN_mp_tc_div_2d) (const mp_int *a, int b, mp_int *c); /* 76 */
          421  +    int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */
   417    422   } TclTomMathStubs;
   418    423   
   419    424   extern const TclTomMathStubs *tclTomMathStubsPtr;
   420    425   
   421    426   #ifdef __cplusplus
   422    427   }
   423    428   #endif
................................................................................
   524    529   	(tclTomMathStubsPtr->tclBN_mp_toradix_n) /* 46 */
   525    530   #define TclBN_mp_unsigned_bin_size \
   526    531   	(tclTomMathStubsPtr->tclBN_mp_unsigned_bin_size) /* 47 */
   527    532   #define TclBN_mp_xor \
   528    533   	(tclTomMathStubsPtr->tclBN_mp_xor) /* 48 */
   529    534   #define TclBN_mp_zero \
   530    535   	(tclTomMathStubsPtr->tclBN_mp_zero) /* 49 */
   531         -#define TclBN_reverse \
   532         -	(tclTomMathStubsPtr->tclBN_reverse) /* 50 */
   533         -#define TclBN_fast_s_mp_mul_digs \
   534         -	(tclTomMathStubsPtr->tclBN_fast_s_mp_mul_digs) /* 51 */
   535         -#define TclBN_fast_s_mp_sqr \
   536         -	(tclTomMathStubsPtr->tclBN_fast_s_mp_sqr) /* 52 */
   537         -#define TclBN_mp_karatsuba_mul \
   538         -	(tclTomMathStubsPtr->tclBN_mp_karatsuba_mul) /* 53 */
   539         -#define TclBN_mp_karatsuba_sqr \
   540         -	(tclTomMathStubsPtr->tclBN_mp_karatsuba_sqr) /* 54 */
   541         -#define TclBN_mp_toom_mul \
   542         -	(tclTomMathStubsPtr->tclBN_mp_toom_mul) /* 55 */
   543         -#define TclBN_mp_toom_sqr \
   544         -	(tclTomMathStubsPtr->tclBN_mp_toom_sqr) /* 56 */
   545         -#define TclBN_s_mp_add \
   546         -	(tclTomMathStubsPtr->tclBN_s_mp_add) /* 57 */
   547         -#define TclBN_s_mp_mul_digs \
   548         -	(tclTomMathStubsPtr->tclBN_s_mp_mul_digs) /* 58 */
   549         -#define TclBN_s_mp_sqr \
   550         -	(tclTomMathStubsPtr->tclBN_s_mp_sqr) /* 59 */
   551         -#define TclBN_s_mp_sub \
   552         -	(tclTomMathStubsPtr->tclBN_s_mp_sub) /* 60 */
          536  +/* Slot 50 is reserved */
          537  +/* Slot 51 is reserved */
          538  +/* Slot 52 is reserved */
          539  +/* Slot 53 is reserved */
          540  +/* Slot 54 is reserved */
          541  +/* Slot 55 is reserved */
          542  +/* Slot 56 is reserved */
          543  +/* Slot 57 is reserved */
          544  +/* Slot 58 is reserved */
          545  +/* Slot 59 is reserved */
          546  +/* Slot 60 is reserved */
   553    547   #define TclBN_mp_init_set_int \
   554    548   	(tclTomMathStubsPtr->tclBN_mp_init_set_int) /* 61 */
   555    549   #define TclBN_mp_set_int \
   556    550   	(tclTomMathStubsPtr->tclBN_mp_set_int) /* 62 */
   557    551   #define TclBN_mp_cnt_lsb \
   558    552   	(tclTomMathStubsPtr->tclBN_mp_cnt_lsb) /* 63 */
   559    553   /* Slot 64 is reserved */
................................................................................
   575    569   	(tclTomMathStubsPtr->tclBN_mp_tc_and) /* 73 */
   576    570   #define TclBN_mp_tc_or \
   577    571   	(tclTomMathStubsPtr->tclBN_mp_tc_or) /* 74 */
   578    572   #define TclBN_mp_tc_xor \
   579    573   	(tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
   580    574   #define TclBN_mp_tc_div_2d \
   581    575   	(tclTomMathStubsPtr->tclBN_mp_tc_div_2d) /* 76 */
          576  +#define TclBN_mp_get_bit \
          577  +	(tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */
   582    578   
   583    579   #endif /* defined(USE_TCL_STUBS) */
   584    580   
   585    581   /* !END!: Do not edit above this line. */
   586    582   
   587    583   #undef TCL_STORAGE_CLASS
   588    584   #define TCL_STORAGE_CLASS DLLIMPORT
   589    585   
   590    586   #endif /* _TCLINTDECLS */

Changes to generic/tclUtf.c.

   263    263   	p += Tcl_UniCharToUtf(-1, p);
   264    264       }
   265    265       Tcl_DStringSetLength(dsPtr, oldLength + (p - string));
   266    266   
   267    267       return string;
   268    268   }
   269    269   
          270  +#if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
          271  +char *
          272  +TclWCharToUtfDString(
          273  +    const WCHAR *uniStr,	/* WCHAR string to convert to UTF-8. */
          274  +    int uniLength,		/* Length of WCHAR string in Tcl_UniChars
          275  +				 * (must be >= 0). */
          276  +    Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
          277  +				 * to this previously initialized DString. */
          278  +{
          279  +    const WCHAR *w, *wEnd;
          280  +    char *p, *string;
          281  +    int oldLength, len = 1;
          282  +
          283  +    /*
          284  +     * UTF-8 string length in bytes will be <= Unicode string length * 4.
          285  +     */
          286  +
          287  +    oldLength = Tcl_DStringLength(dsPtr);
          288  +    Tcl_DStringSetLength(dsPtr, oldLength + (uniLength + 1) * 4);
          289  +    string = Tcl_DStringValue(dsPtr) + oldLength;
          290  +
          291  +    p = string;
          292  +    wEnd = uniStr + uniLength;
          293  +    for (w = uniStr; w < wEnd; ) {
          294  +	if (!len && ((*w & 0xFC00) != 0xDC00)) {
          295  +	    /* Special case for handling high surrogates. */
          296  +	    p += Tcl_UniCharToUtf(-1, p);
          297  +	}
          298  +	len = Tcl_UniCharToUtf(*w, p);
          299  +	p += len;
          300  +	if ((*w >= 0xD800) && (len < 3)) {
          301  +	    len = 0; /* Indication that high surrogate was found */
          302  +	}
          303  +	w++;
          304  +    }
          305  +    if (!len) {
          306  +	/* Special case for handling high surrogates. */
          307  +	p += Tcl_UniCharToUtf(-1, p);
          308  +    }
          309  +    Tcl_DStringSetLength(dsPtr, oldLength + (p - string));
          310  +
          311  +    return string;
          312  +}
          313  +#endif
   270    314   /*
   271    315    *---------------------------------------------------------------------------
   272    316    *
   273    317    * Tcl_UtfToUniChar --
   274    318    *
   275    319    *	Extract the Tcl_UniChar represented by the UTF-8 string. Bad UTF-8
   276    320    *	sequences are converted to valid Tcl_UniChars and processing
................................................................................
   414    458   	 * represents itself.
   415    459   	 */
   416    460       }
   417    461   
   418    462       *chPtr = byte;
   419    463       return 1;
   420    464   }
   421         -
          465  +
          466  +#if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
          467  +int
          468  +TclUtfToWChar(
          469  +    const char *src,	/* The UTF-8 string. */
          470  +    WCHAR *chPtr)/* Filled with the WCHAR represented by
          471  +				 * the UTF-8 string. */
          472  +{
          473  +    WCHAR byte;
          474  +
          475  +    /*
          476  +     * Unroll 1 to 4 byte UTF-8 sequences.
          477  +     */
          478  +
          479  +    byte = *((unsigned char *) src);
          480  +    if (byte < 0xC0) {
          481  +	/*
          482  +	 * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
          483  +	 * Treats naked trail bytes 0x80 to 0x9F as valid characters from
          484  +	 * the cp1252 table. See: <https://en.wikipedia.org/wiki/UTF-8>
          485  +	 * Also treats \0 and other naked trail bytes 0xA0 to 0xBF as valid
          486  +	 * characters representing themselves.
          487  +	 */
          488  +
          489  +	/* If *chPtr contains a high surrogate (produced by a previous
          490  +	 * Tcl_UtfToUniChar() call) and the next 3 bytes are UTF-8 continuation
          491  +	 * bytes, then we must produce a follow-up low surrogate. We only
          492  +	 * do that if the high surrogate matches the bits we encounter.
          493  +	 */
          494  +	if ((byte >= 0x80)
          495  +		&& (((((byte - 0x10) << 2) & 0xFC) | 0xD800) == (*chPtr & 0xFCFC))
          496  +		&& ((src[1] & 0xF0) == (((*chPtr << 4) & 0x30) | 0x80))
          497  +		&& ((src[2] & 0xC0) == 0x80)) {
          498  +	    *chPtr = ((src[1] & 0x0F) << 6) + (src[2] & 0x3F) + 0xDC00;
          499  +	    return 3;
          500  +	}
          501  +	if ((unsigned)(byte-0x80) < (unsigned)0x20) {
          502  +	    *chPtr = cp1252[byte-0x80];
          503  +	} else {
          504  +	    *chPtr = byte;
          505  +	}
          506  +	return 1;
          507  +    } else if (byte < 0xE0) {
          508  +	if ((src[1] & 0xC0) == 0x80) {
          509  +	    /*
          510  +	     * Two-byte-character lead-byte followed by a trail-byte.
          511  +	     */
          512  +
          513  +	    *chPtr = (((byte & 0x1F) << 6) | (src[1] & 0x3F));
          514  +	    if ((unsigned)(*chPtr - 1) >= (UNICODE_SELF - 1)) {
          515  +		return 2;
          516  +	    }
          517  +	}
          518  +
          519  +	/*
          520  +	 * A two-byte-character lead-byte not followed by trail-byte
          521  +	 * represents itself.
          522  +	 */
          523  +    } else if (byte < 0xF0) {
          524  +	if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80)) {
          525  +	    /*
          526  +	     * Three-byte-character lead byte followed by two trail bytes.
          527  +	     */
          528  +
          529  +	    *chPtr = (((byte & 0x0F) << 12)
          530  +		    | ((src[1] & 0x3F) << 6) | (src[2] & 0x3F));
          531  +	    if (*chPtr > 0x7FF) {
          532  +		return 3;
          533  +	    }
          534  +	}
          535  +
          536  +	/*
          537  +	 * A three-byte-character lead-byte not followed by two trail-bytes
          538  +	 * represents itself.
          539  +	 */
          540  +    }
          541  +    else if (byte < 0xF8) {
          542  +	if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80) && ((src[3] & 0xC0) == 0x80)) {
          543  +	    /*
          544  +	     * Four-byte-character lead byte followed by three trail bytes.
          545  +	     */
          546  +	    WCHAR high = (((byte & 0x07) << 8) | ((src[1] & 0x3F) << 2)
          547  +		    | ((src[2] & 0x3F) >> 4)) - 0x40;
          548  +	    if (high >= 0x400) {
          549  +		/* out of range, < 0x10000 or > 0x10ffff */
          550  +	    } else {
          551  +		/* produce high surrogate, advance source pointer */
          552  +		*chPtr = 0xD800 + high;
          553  +		return 1;
          554  +	    }
          555  +	}
          556  +
          557  +	/*
          558  +	 * A four-byte-character lead-byte not followed by three trail-bytes
          559  +	 * represents itself.
          560  +	 */
          561  +    }
          562  +
          563  +    *chPtr = byte;
          564  +    return 1;
          565  +}
          566  +#endif
          567  +
   422    568   /*
   423    569    *---------------------------------------------------------------------------
   424    570    *
   425    571    * Tcl_UtfToUniCharDString --
   426    572    *
   427    573    *	Convert the UTF-8 string to Unicode.
   428    574    *
................................................................................
   485    631       }
   486    632       *w = '\0';
   487    633       Tcl_DStringSetLength(dsPtr,
   488    634   	    oldLength + ((char *) w - (char *) wString));
   489    635   
   490    636       return wString;
   491    637   }
   492         -
          638  +
          639  +#if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
          640  +WCHAR *
          641  +TclUtfToWCharDString(
          642  +    const char *src,		/* UTF-8 string to convert to Unicode. */
          643  +    int length,			/* Length of UTF-8 string in bytes, or -1 for
          644  +				 * strlen(). */
          645  +    Tcl_DString *dsPtr)		/* Unicode representation of string is
          646  +				 * appended to this previously initialized
          647  +				 * DString. */
          648  +{
          649  +    WCHAR ch = 0, *w, *wString;
          650  +    const char *p, *end;
          651  +    int oldLength;
          652  +
          653  +    if (length < 0) {
          654  +	length = strlen(src);
          655  +    }
          656  +
          657  +    /*
          658  +     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
          659  +     * bytes.
          660  +     */
          661  +
          662  +    oldLength = Tcl_DStringLength(dsPtr);
          663  +
          664  +    Tcl_DStringSetLength(dsPtr,
          665  +	    oldLength + (int) ((length + 1) * sizeof(WCHAR)));
          666  +    wString = (WCHAR *) (Tcl_DStringValue(dsPtr) + oldLength);
          667  +
          668  +    w = wString;
          669  +    p = src;
          670  +    end = src + length - 4;
          671  +    while (p < end) {
          672  +	p += TclUtfToWChar(p, &ch);
          673  +	*w++ = ch;
          674  +    }
          675  +    end += 4;
          676  +    while (p < end) {
          677  +	if (Tcl_UtfCharComplete(p, end-p)) {
          678  +	    p += TclUtfToWChar(p, &ch);
          679  +	} else if (((UCHAR(*p)-0x80)) < 0x20) {
          680  +	    ch = cp1252[UCHAR(*p++)-0x80];
          681  +	} else {
          682  +	    ch = UCHAR(*p++);
          683  +	}
          684  +	*w++ = ch;
          685  +    }
          686  +    *w = '\0';
          687  +    Tcl_DStringSetLength(dsPtr,
          688  +	    oldLength + ((char *) w - (char *) wString));
          689  +
          690  +    return wString;
          691  +}
          692  +#endif
   493    693   /*
   494    694    *---------------------------------------------------------------------------
   495    695    *
   496    696    * Tcl_UtfCharComplete --
   497    697    *
   498    698    *	Determine if the UTF-8 string of the given length is long enough to be
   499    699    *	decoded by Tcl_UtfToUniChar(). This does not ensure that the UTF-8
................................................................................
  2002   2202   	 * characters separated by "-").
  2003   2203   	 */
  2004   2204   
  2005   2205   	if (p == '[') {
  2006   2206   	    Tcl_UniChar startChar, endChar;
  2007   2207   
  2008   2208   	    uniPattern++;
  2009         -	    ch1 = (nocase ? Tcl_UniCharToLower(*uniStr) : *uniStr);
         2209  +	    ch1 = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*uniStr) : *uniStr);
  2010   2210   	    uniStr++;
  2011   2211   	    while (1) {
  2012   2212   		if ((*uniPattern == ']') || (*uniPattern == 0)) {
  2013   2213   		    return 0;
  2014   2214   		}
  2015         -		startChar = (nocase ? Tcl_UniCharToLower(*uniPattern)
         2215  +		startChar = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*uniPattern)
  2016   2216   			: *uniPattern);
  2017   2217   		uniPattern++;
  2018   2218   		if (*uniPattern == '-') {
  2019   2219   		    uniPattern++;
  2020   2220   		    if (*uniPattern == 0) {
  2021   2221   			return 0;
  2022   2222   		    }
  2023         -		    endChar = (nocase ? Tcl_UniCharToLower(*uniPattern)
         2223  +		    endChar = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*uniPattern)
  2024   2224   			    : *uniPattern);
  2025   2225   		    uniPattern++;
  2026   2226   		    if (((startChar <= ch1) && (ch1 <= endChar))
  2027   2227   			    || ((endChar <= ch1) && (ch1 <= startChar))) {
  2028   2228   			/*
  2029   2229   			 * Matches ranges of form [a-z] or [z-a].
  2030   2230   			 */
................................................................................
  2195   2395   	 * characters separated by "-").
  2196   2396   	 */
  2197   2397   
  2198   2398   	if (p == '[') {
  2199   2399   	    Tcl_UniChar ch1, startChar, endChar;
  2200   2400   
  2201   2401   	    pattern++;
  2202         -	    ch1 = (nocase ? Tcl_UniCharToLower(*string) : *string);
         2402  +	    ch1 = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*string) : *string);
  2203   2403   	    string++;
  2204   2404   	    while (1) {
  2205   2405   		if ((*pattern == ']') || (pattern == patternEnd)) {
  2206   2406   		    return 0;
  2207   2407   		}
  2208         -		startChar = (nocase ? Tcl_UniCharToLower(*pattern) : *pattern);
         2408  +		startChar = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*pattern) : *pattern);
  2209   2409   		pattern++;
  2210   2410   		if (*pattern == '-') {
  2211   2411   		    pattern++;
  2212   2412   		    if (pattern == patternEnd) {
  2213   2413   			return 0;
  2214   2414   		    }
  2215         -		    endChar = (nocase ? Tcl_UniCharToLower(*pattern)
         2415  +		    endChar = (nocase ? (Tcl_UniChar)Tcl_UniCharToLower(*pattern)
  2216   2416   			    : *pattern);
  2217   2417   		    pattern++;
  2218   2418   		    if (((startChar <= ch1) && (ch1 <= endChar))
  2219   2419   			    || ((endChar <= ch1) && (ch1 <= startChar))) {
  2220   2420   			/*
  2221   2421   			 * Matches ranges of form [a-z] or [z-a].
  2222   2422   			 */

Changes to generic/tclUtil.c.

   877    877   	const char *prevList = list;
   878    878   	int literal;
   879    879   
   880    880   	result = TclFindElement(interp, list, length, &element, &list,
   881    881   		&elSize, &literal);
   882    882   	length -= (list - prevList);
   883    883   	if (result != TCL_OK) {
   884         -	    Tcl_Free(argv);
          884  +	    Tcl_Free((void *)argv);
   885    885   	    return result;
   886    886   	}
   887    887   	if (*element == 0) {
   888    888   	    break;
   889    889   	}
   890    890   	if (i >= size) {
   891         -	    Tcl_Free(argv);
          891  +	    Tcl_Free((void *)argv);
   892    892   	    if (interp != NULL) {
   893    893   		Tcl_SetObjResult(interp, Tcl_NewStringObj(
   894    894   			"internal error in Tcl_SplitList", -1));
   895    895   		Tcl_SetErrorCode(interp, "TCL", "INTERNAL", "Tcl_SplitList",
   896    896   			NULL);
   897    897   	    }
   898    898   	    return TCL_ERROR;
................................................................................
  2234   2234   		 * character
  2235   2235   		 */
  2236   2236   
  2237   2237   		if ((p != '[') && (p != '?') && (p != '\\')) {
  2238   2238   		    if (nocase) {
  2239   2239   			while (*str) {
  2240   2240   			    charLen = TclUtfToUniChar(str, &ch1);
  2241         -			    if (ch2==ch1 || ch2==Tcl_UniCharToLower(ch1)) {
         2241  +			    if (ch2==ch1 || ch2==(Tcl_UniChar)Tcl_UniCharToLower(ch1)) {
  2242   2242   				break;
  2243   2243   			    }
  2244   2244   			    str += charLen;
  2245   2245   			}
  2246   2246   		    } else {
  2247   2247   			/*
  2248   2248   			 * There's no point in trying to make this code
................................................................................
  2582   2582   TclStringMatchObj(
  2583   2583       Tcl_Obj *strObj,		/* string object. */
  2584   2584       Tcl_Obj *ptnObj,		/* pattern object. */
  2585   2585       int flags)			/* Only TCL_MATCH_NOCASE should be passed, or
  2586   2586   				 * 0. */
  2587   2587   {
  2588   2588       int match;
  2589         -    size_t length, plen;
         2589  +    size_t length = 0, plen = 0;
  2590   2590   
  2591   2591       /*
  2592   2592        * Promote based on the type of incoming object.
  2593   2593        * XXX: Currently doesn't take advantage of exact-ness that
  2594   2594        * XXX: TclReToGlob tells us about
  2595   2595       trivial = nocase ? 0 : TclMatchIsTrivial(TclGetString(ptnObj));
  2596   2596        */

Changes to generic/tclZipfs.c.

  1899   1899       void *clientData,	/* Not used. */
  1900   1900       Tcl_Interp *interp,		/* Current interpreter. */
  1901   1901       int objc,			/* Number of arguments. */
  1902   1902       Tcl_Obj *const objv[])	/* Argument objects. */
  1903   1903   {
  1904   1904       const char *mountPoint;	/* Mount point path. */
  1905   1905       unsigned char *data;
  1906         -    size_t length;
         1906  +    size_t length = 0;
  1907   1907   
  1908   1908       if (objc > 4) {
  1909   1909   	Tcl_WrongNumArgs(interp, 1, objv, "?mountpoint? ?data?");
  1910   1910   	return TCL_ERROR;
  1911   1911       }
  1912   1912       if (objc < 2) {
  1913   1913   	int ret;
................................................................................
  4829   4829    *-------------------------------------------------------------------------
  4830   4830    */
  4831   4831   
  4832   4832   int
  4833   4833   TclZipfs_AppHook(
  4834   4834       int *argcPtr,		/* Pointer to argc */
  4835   4835   #ifdef _WIN32
  4836         -    TCHAR
         4836  +    WCHAR
  4837   4837   #else /* !_WIN32 */
  4838   4838       char
  4839   4839   #endif /* _WIN32 */
  4840   4840       ***argvPtr)			/* Pointer to argv */
  4841   4841   {
  4842   4842       char *archive;
  4843   4843   

Changes to generic/tclZlib.c.

   587    587   
   588    588   static int
   589    589   SetInflateDictionary(
   590    590       z_streamp strm,
   591    591       Tcl_Obj *compDictObj)
   592    592   {
   593    593       if (compDictObj != NULL) {
   594         -	size_t length;
          594  +	size_t length = 0;
   595    595   	unsigned char *bytes = TclGetByteArrayFromObj(compDictObj, &length);
   596    596   
   597    597   	return inflateSetDictionary(strm, bytes, length);
   598    598       }
   599    599       return Z_OK;
   600    600   }
   601    601   
   602    602   static int
   603    603   SetDeflateDictionary(
   604    604       z_streamp strm,
   605    605       Tcl_Obj *compDictObj)
   606    606   {
   607    607       if (compDictObj != NULL) {
   608         -	size_t length;
          608  +	size_t length = 0;
   609    609   	unsigned char *bytes = TclGetByteArrayFromObj(compDictObj, &length);
   610    610   
   611    611   	return deflateSetDictionary(strm, bytes, length);
   612    612       }
   613    613       return Z_OK;
   614    614   }
   615    615   
................................................................................
  1186   1186       Tcl_Obj *data,		/* Data to compress/decompress */
  1187   1187       int flush)			/* TCL_ZLIB_NO_FLUSH, TCL_ZLIB_FLUSH,
  1188   1188   				 * TCL_ZLIB_FULLFLUSH, or TCL_ZLIB_FINALIZE */
  1189   1189   {
  1190   1190       ZlibStreamHandle *zshPtr = (ZlibStreamHandle *) zshandle;
  1191   1191       char *dataTmp = NULL;
  1192   1192       int e;
  1193         -    size_t size, outSize, toStore;
         1193  +    size_t size = 0, outSize, toStore;
  1194   1194   
  1195   1195       if (zshPtr->streamEnd) {
  1196   1196   	if (zshPtr->interp) {
  1197   1197   	    Tcl_SetObjResult(zshPtr->interp, Tcl_NewStringObj(
  1198   1198   		    "already past compressed stream end", -1));
  1199   1199   	    Tcl_SetErrorCode(zshPtr->interp, "TCL", "ZIP", "CLOSED", NULL);
  1200   1200   	}
................................................................................
  1310   1310       Tcl_ZlibStream zshandle,	/* As obtained from Tcl_ZlibStreamInit */
  1311   1311       Tcl_Obj *data,		/* A place to append the data. */
  1312   1312       size_t count)			/* Number of bytes to grab as a maximum, you
  1313   1313   				 * may get less! */
  1314   1314   {
  1315   1315       ZlibStreamHandle *zshPtr = (ZlibStreamHandle *) zshandle;
  1316   1316       int e, i, listLen;
  1317         -    size_t itemLen, dataPos = 0;
         1317  +    size_t itemLen = 0, dataPos = 0;
  1318   1318       Tcl_Obj *itemObj;
  1319   1319       unsigned char *dataPtr, *itemPtr;
  1320         -    size_t existing;
         1320  +    size_t existing = 0;
  1321   1321   
  1322   1322       /*
  1323   1323        * Getting beyond the of stream, just return empty string.
  1324   1324        */
  1325   1325   
  1326   1326       if (zshPtr->streamEnd) {
  1327   1327   	return TCL_OK;
................................................................................
  1925   1925   ZlibCmd(
  1926   1926       void *notUsed,
  1927   1927       Tcl_Interp *interp,
  1928   1928       int objc,
  1929   1929       Tcl_Obj *const objv[])
  1930   1930   {
  1931   1931       int command, i, option, level = -1;
  1932         -    size_t dlen, start, buffersize = 0;
         1932  +    size_t dlen = 0, start, buffersize = 0;
  1933   1933       Tcl_WideInt wideLen;
  1934   1934       Byte *data;
  1935   1935       Tcl_Obj *headerDictObj;
  1936   1936       const char *extraInfoStr = NULL;
  1937   1937       static const char *const commands[] = {
  1938   1938   	"adler32", "compress", "crc32", "decompress", "deflate", "gunzip",
  1939   1939   	"gzip", "inflate", "push", "stream",
................................................................................
  2736   2736       }
  2737   2737   
  2738   2738       /*
  2739   2739        * Set the compression dictionary if requested.
  2740   2740        */
  2741   2741   
  2742   2742       if (compDictObj != NULL) {
  2743         -	size_t len;
         2743  +	size_t len = 0;
  2744   2744   
  2745   2745   	(void) TclGetByteArrayFromObj(compDictObj, &len);
  2746   2746   	if (len == 0) {
  2747   2747   	    compDictObj = NULL;
  2748   2748   	}
  2749   2749   	Tcl_ZlibStreamSetCompressionDictionary(zstream, compDictObj);
  2750   2750       }
................................................................................
  2840   2840       }
  2841   2841   
  2842   2842       /*
  2843   2843        * Set the compression dictionary if requested.
  2844   2844        */
  2845   2845   
  2846   2846       if (compDictObj != NULL) {
  2847         -	size_t len;
         2847  +	size_t len = 0;
  2848   2848   
  2849   2849   	(void) TclGetByteArrayFromObj(compDictObj, &len);
  2850   2850   	if (len == 0) {
  2851   2851   	    compDictObj = NULL;
  2852   2852   	}
  2853   2853   	Tcl_ZlibStreamSetCompressionDictionary(zstream, compDictObj);
  2854   2854       }

Changes to tests/encoding.test.

    32     32   proc runtests {} {
    33     33       variable x
    34     34   
    35     35   # Some tests require the testencoding command
    36     36   testConstraint testencoding [llength [info commands testencoding]]
    37     37   testConstraint testbytestring [llength [info commands testbytestring]]
    38     38   testConstraint teststringbytes [llength [info commands teststringbytes]]
    39         -testConstraint tip389 [expr {[string length \U010000] == 2}]
    40     39   testConstraint exec [llength [info commands exec]]
    41     40   testConstraint testgetencpath [llength [info commands testgetencpath]]
    42     41   
    43     42   # TclInitEncodingSubsystem is tested by the rest of this file
    44     43   # TclFinalizeEncodingSubsystem is not currently tested
    45     44   
    46     45   test encoding-1.1 {Tcl_GetEncoding: system encoding} -setup {
................................................................................
   319    318   } 00
   320    319   test encoding-15.3 {UtfToUtfProc null character input} teststringbytes {
   321    320       set y [encoding convertfrom utf-8 [encoding convertto utf-8 \u0000]]
   322    321       binary scan [teststringbytes $y] H* z
   323    322       set z
   324    323   } c080
   325    324   
   326         -test encoding-16.1 {UnicodeToUtfProc} -constraints tip389 -body {
          325  +test encoding-16.1 {UnicodeToUtfProc} -body {
   327    326       set val [encoding convertfrom unicode NN]
   328    327       list $val [format %x [scan $val %c]]
   329    328   } -result "\u4e4e 4e4e"
   330         -test encoding-16.2 {UnicodeToUtfProc} -constraints tip389 -body {
          329  +test encoding-16.2 {UnicodeToUtfProc} -body {
   331    330       set val [encoding convertfrom unicode "\xd8\xd8\xdc\xdc"]
   332    331       list $val [format %x [scan $val %c]]
   333    332   } -result "\U460dc 460dc"
   334    333   
   335         -test encoding-17.1 {UtfToUnicodeProc} -constraints tip389 -body {
          334  +test encoding-17.1 {UtfToUnicodeProc} -body {
   336    335       encoding convertto unicode "\U460dc"
   337    336   } -result "\xd8\xd8\xdc\xdc"
   338    337   
   339    338   test encoding-18.1 {TableToUtfProc} {
   340    339   } {}
   341    340   
   342    341   test encoding-19.1 {TableFromUtfProc} {

Changes to unix/Makefile.in.

   321    321   
   322    322   TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \
   323    323   	bn_fast_s_mp_sqr.o bn_mp_add.o bn_mp_and.o \
   324    324   	bn_mp_add_d.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o \
   325    325   	bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
   326    326   	bn_mp_cnt_lsb.o bn_mp_copy.o \
   327    327   	bn_mp_count_bits.o bn_mp_div.o bn_mp_div_d.o bn_mp_div_2.o \
   328         -	bn_mp_div_2d.o bn_mp_div_3.o \
   329         -	bn_mp_exch.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_get_int.o \
          328  +	bn_mp_div_2d.o bn_mp_div_3.o bn_mp_exch.o \
          329  +	bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_get_bit.o bn_mp_get_int.o \
   330    330   	bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_init.o \
   331    331   	bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \
   332    332   	bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_karatsuba_mul.o \
   333    333   	bn_mp_karatsuba_sqr.o \
   334    334   	bn_mp_lshd.o bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mul.o bn_mp_mul_2.o \
   335    335   	bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_neg.o bn_mp_or.o \
   336    336   	bn_mp_radix_size.o bn_mp_radix_smap.o \
................................................................................
  1539   1539   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_exch.c
  1540   1540   
  1541   1541   bn_mp_expt_d.o: $(TOMMATH_DIR)/bn_mp_expt_d.c $(MATHHDRS)
  1542   1542   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d.c
  1543   1543   
  1544   1544   bn_mp_expt_d_ex.o: $(TOMMATH_DIR)/bn_mp_expt_d_ex.c $(MATHHDRS)
  1545   1545   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d_ex.c
         1546  +
         1547  +bn_mp_get_bit.o: $(TOMMATH_DIR)/bn_mp_get_bit.c $(MATHHDRS)
         1548  +	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_bit.c
  1546   1549   
  1547   1550   bn_mp_get_int.o: $(TOMMATH_DIR)/bn_mp_get_int.c $(MATHHDRS)
  1548   1551   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_int.c
  1549   1552   
  1550   1553   bn_mp_get_long.o: $(TOMMATH_DIR)/bn_mp_get_long.c $(MATHHDRS)
  1551   1554   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_long.c
  1552   1555   

Changes to unix/tclUnixChan.c.

   650    650       }
   651    651   
   652    652       /*
   653    653        * Option -xchar {\x11 \x13}
   654    654        */
   655    655   
   656    656       if ((len > 1) && (strncmp(optionName, "-xchar", len) == 0)) {
   657         -	Tcl_DString ds;
   658         -
   659    657   	if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
   660    658   	    return TCL_ERROR;
   661    659   	} else if (argc != 2) {
          660  +	badXchar:
   662    661   	    if (interp) {
   663    662   		Tcl_SetObjResult(interp, Tcl_NewStringObj(
   664    663   			"bad value for -xchar: should be a list of"
   665         -			" two elements", -1));
   666         -		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
   667         -			"VALUE", NULL);
          664  +			" two elements with each a single 8-bit character", -1));
          665  +		Tcl_SetErrorCode(interp, "TCL", "VALUE", "XCHAR", NULL);
   668    666   	    }
   669    667   	    Tcl_Free(argv);
   670    668   	    return TCL_ERROR;
   671    669   	}
   672    670   
   673    671   	tcgetattr(fsPtr->fd, &iostate);
   674    672   
   675         -	Tcl_UtfToExternalDString(NULL, argv[0], -1, &ds);
   676         -	iostate.c_cc[VSTART] = *(const cc_t *) Tcl_DStringValue(&ds);
   677         -	TclDStringClear(&ds);
          673  +	iostate.c_cc[VSTART] = argv[0][0];
          674  +	iostate.c_cc[VSTOP] = argv[1][0];
          675  +	if (argv[0][0] & 0x80 || argv[1][0] & 0x80) {
          676  +	    Tcl_UniChar character = 0;
          677  +	    int charLen;
   678    678   
   679         -	Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds);
   680         -	iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds);
   681         -	Tcl_DStringFree(&ds);
          679  +	    charLen = Tcl_UtfToUniChar(argv[0], &character);
          680  +	    if ((character > 0xFF) || argv[0][charLen]) {
          681  +		goto badXchar;
          682  +	    }
          683  +	    iostate.c_cc[VSTART] = character;
          684  +	    charLen = Tcl_UtfToUniChar(argv[1], &character);
          685  +	    if ((character > 0xFF) || argv[1][charLen]) {
          686  +		goto badXchar;
          687  +	    }
          688  +	    iostate.c_cc[VSTOP] = character;
          689  +	}
   682    690   	Tcl_Free(argv);
   683    691   
   684    692   	tcsetattr(fsPtr->fd, TCSADRAIN, &iostate);
   685    693   	return TCL_OK;
   686    694       }
   687    695   
   688    696       /*

Changes to win/Makefile.in.

   380    380   	bn_mp_div_d.${OBJEXT} \
   381    381   	bn_mp_div_2.${OBJEXT} \
   382    382   	bn_mp_div_2d.${OBJEXT} \
   383    383   	bn_mp_div_3.${OBJEXT} \
   384    384   	bn_mp_exch.${OBJEXT} \
   385    385   	bn_mp_expt_d.${OBJEXT} \
   386    386   	bn_mp_expt_d_ex.${OBJEXT} \
          387  +	bn_mp_get_bit.${OBJEXT} \
   387    388   	bn_mp_get_int.${OBJEXT} \
   388    389   	bn_mp_get_long.${OBJEXT} \
   389    390   	bn_mp_get_long_long.${OBJEXT} \
   390    391   	bn_mp_grow.${OBJEXT} \
   391    392   	bn_mp_init.${OBJEXT} \
   392    393   	bn_mp_init_copy.${OBJEXT} \
   393    394   	bn_mp_init_multi.${OBJEXT} \

Changes to win/makefile.vc.

   272    272   	$(TMP_DIR)\bn_mp_div_d.obj \
   273    273   	$(TMP_DIR)\bn_mp_div_2.obj \
   274    274   	$(TMP_DIR)\bn_mp_div_2d.obj \
   275    275   	$(TMP_DIR)\bn_mp_div_3.obj \
   276    276   	$(TMP_DIR)\bn_mp_exch.obj \
   277    277   	$(TMP_DIR)\bn_mp_expt_d.obj \
   278    278   	$(TMP_DIR)\bn_mp_expt_d_ex.obj \
          279  +	$(TMP_DIR)\bn_mp_get_bit.obj \
   279    280   	$(TMP_DIR)\bn_mp_get_int.obj \
   280    281   	$(TMP_DIR)\bn_mp_get_long.obj \
   281    282   	$(TMP_DIR)\bn_mp_get_long_long.obj \
   282    283   	$(TMP_DIR)\bn_mp_grow.obj \
   283    284   	$(TMP_DIR)\bn_mp_init.obj \
   284    285   	$(TMP_DIR)\bn_mp_init_copy.obj \
   285    286   	$(TMP_DIR)\bn_mp_init_multi.obj \

Changes to win/tclWin32Dll.c.

    42     42   /*
    43     43    * The following structure and linked list is to allow us to map between
    44     44    * volume mount points and drive letters on the fly (no Win API exists for
    45     45    * this).
    46     46    */
    47     47   
    48     48   typedef struct MountPointMap {
    49         -    TCHAR *volumeName;		/* Native wide string volume name. */
    50         -    TCHAR driveLetter;		/* Drive letter corresponding to the volume
           49  +    WCHAR *volumeName;		/* Native wide string volume name. */
           50  +    WCHAR driveLetter;		/* Drive letter corresponding to the volume
    51     51   				 * name. */
    52     52       struct MountPointMap *nextPtr;
    53     53   				/* Pointer to next structure in list, or
    54     54   				 * NULL. */
    55     55   } MountPointMap;
    56     56   
    57     57   /*
................................................................................
   282    282    *	mount point.
   283    283    *
   284    284    *--------------------------------------------------------------------
   285    285    */
   286    286   
   287    287   char
   288    288   TclWinDriveLetterForVolMountPoint(
   289         -    const TCHAR *mountPoint)
          289  +    const WCHAR *mountPoint)
   290    290   {
   291    291       MountPointMap *dlIter, *dlPtr2;
   292         -    TCHAR Target[55];		/* Target of mount at mount point */
   293         -    TCHAR drive[4] = TEXT("A:\\");
          292  +    WCHAR Target[55];		/* Target of mount at mount point */
          293  +    WCHAR drive[4] = TEXT("A:\\");
   294    294   
   295    295       /*
   296    296        * Detect the volume mounted there. Unfortunately, there is no simple way
   297    297        * to map a unique volume name to a DOS drive letter. So, we have to build
   298    298        * an associative array.
   299    299        */
   300    300   
   301    301       Tcl_MutexLock(&mountPointMap);
   302    302       dlIter = driveLetterLookup;
   303    303       while (dlIter != NULL) {
   304         -	if (_tcscmp(dlIter->volumeName, mountPoint) == 0) {
          304  +	if (wcscmp(dlIter->volumeName, mountPoint) == 0) {
   305    305   	    /*
   306    306   	     * We need to check whether this information is still valid, since
   307    307   	     * either the user or various programs could have adjusted the
   308    308   	     * mount points on the fly.
   309    309   	     */
   310    310   
   311         -	    drive[0] = (TCHAR) dlIter->driveLetter;
          311  +	    drive[0] = (WCHAR) dlIter->driveLetter;
   312    312   
   313    313   	    /*
   314    314   	     * Try to read the volume mount point and see where it points.
   315    315   	     */
   316    316   
   317    317   	    if (GetVolumeNameForVolumeMountPoint(drive,
   318    318   		    Target, 55) != 0) {
   319         -		if (_tcscmp(dlIter->volumeName, Target) == 0) {
          319  +		if (wcscmp(dlIter->volumeName, Target) == 0) {
   320    320   		    /*
   321    321   		     * Nothing has changed.
   322    322   		     */
   323    323   
   324    324   		    Tcl_MutexUnlock(&mountPointMap);
   325    325   		    return (char) dlIter->driveLetter;
   326    326   		}
................................................................................
   375    375   
   376    376   	if (GetVolumeNameForVolumeMountPoint(drive,
   377    377   		Target, 55) != 0) {
   378    378   	    int alreadyStored = 0;
   379    379   
   380    380   	    for (dlIter = driveLetterLookup; dlIter != NULL;
   381    381   		    dlIter = dlIter->nextPtr) {
   382         -		if (_tcscmp(dlIter->volumeName, Target) == 0) {
          382  +		if (wcscmp(dlIter->volumeName, Target) == 0) {
   383    383   		    alreadyStored = 1;
   384    384   		    break;
   385    385   		}
   386    386   	    }
   387    387   	    if (!alreadyStored) {
   388    388   		dlPtr2 = Tcl_Alloc(sizeof(MountPointMap));
   389    389   		dlPtr2->volumeName = TclNativeDupInternalRep(Target);
................................................................................
   396    396   
   397    397       /*
   398    398        * Try again.
   399    399        */
   400    400   
   401    401       for (dlIter = driveLetterLookup; dlIter != NULL;
   402    402   	    dlIter = dlIter->nextPtr) {
   403         -	if (_tcscmp(dlIter->volumeName, mountPoint) == 0) {
          403  +	if (wcscmp(dlIter->volumeName, mountPoint) == 0) {
   404    404   	    Tcl_MutexUnlock(&mountPointMap);
   405    405   	    return (char) dlIter->driveLetter;
   406    406   	}
   407    407       }
   408    408   
   409    409       /*
   410    410        * The volume doesn't appear to correspond to a drive letter - we remember
................................................................................
   443    443    *	This saves you the trouble of writing the
   444    444    *	following type of fragment over and over:
   445    445    *
   446    446    *		encoding <- Tcl_GetEncoding("unicode");
   447    447    *		nativeBuffer <- UtfToExternal(encoding, utfBuffer);
   448    448    *		Tcl_FreeEncoding(encoding);
   449    449    *
   450         - *	By convention, in Windows a TCHAR is a Unicode character. If you plan
          450  + *	By convention, in Windows a WCHAR is a Unicode character. If you plan
   451    451    *	on targeting a Unicode interface when running on Windows, these
   452    452    *	functions should be used. If you plan on targetting a "char" oriented
   453    453    *	function on Windows, use Tcl_UtfToExternal() with an encoding of NULL.
   454    454    *
   455    455    * Results:
   456    456    *	The result is a pointer to the string in the desired target encoding.
   457    457    *	Storage for the result string is allocated in dsPtr; the caller must
................................................................................
   459    459    *
   460    460    * Side effects:
   461    461    *	None.
   462    462    *
   463    463    *---------------------------------------------------------------------------
   464    464    */
   465    465   
   466         -TCHAR *
          466  +WCHAR *
   467    467   Tcl_WinUtfToTChar(
   468    468       const char *string,		/* Source string in UTF-8. */
   469    469       size_t len,			/* Source string length in bytes, or -1
   470    470   				 * for strlen(). */
   471    471       Tcl_DString *dsPtr)		/* Uninitialized or free DString in which the
   472    472   				 * converted string is stored. */
   473    473   {
   474         -#if TCL_UTF_MAX > 4
   475         -    Tcl_UniChar ch = 0;
   476         -    TCHAR *w, *wString;
   477         -    const char *p, *end;
   478         -    int oldLength;
   479         -#endif
   480         -
   481    474       Tcl_DStringInit(dsPtr);
   482    475       if (!string) {
   483    476   	return NULL;
   484    477       }
   485         -#if TCL_UTF_MAX > 4
   486         -
   487         -    if (len < 0) {
   488         -	len = strlen(string);
   489         -    }
   490         -
   491         -    /*
   492         -     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
   493         -     * bytes.
   494         -     */
   495         -
   496         -    oldLength = Tcl_DStringLength(dsPtr);
   497         -
   498         -    Tcl_DStringSetLength(dsPtr,
   499         -	    oldLength + (int) ((len + 1) * sizeof(TCHAR)));
   500         -    wString = (TCHAR *) (Tcl_DStringValue(dsPtr) + oldLength);
   501         -
   502         -    w = wString;
   503         -    p = string;
   504         -    end = string + len - 4;
   505         -    while (p < end) {
   506         -	p += TclUtfToUniChar(p, &ch);
   507         -	if (ch > 0xFFFF) {
   508         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   509         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   510         -	} else {
   511         -	    *w++ = ch;
   512         -	}
   513         -    }
   514         -    end += 4;
   515         -    while (p < end) {
   516         -	if (Tcl_UtfCharComplete(p, end-p)) {
   517         -	    p += TclUtfToUniChar(p, &ch);
   518         -	} else {
   519         -	    ch = UCHAR(*p++);
   520         -	}
   521         -	if (ch > 0xFFFF) {
   522         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   523         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   524         -	} else {
   525         -	    *w++ = ch;
   526         -	}
   527         -    }
   528         -    *w = '\0';
   529         -    Tcl_DStringSetLength(dsPtr,
   530         -	    oldLength + ((char *) w - (char *) wString));
   531         -
   532         -    return wString;
   533         -#else
   534         -    return Tcl_UtfToUniCharDString(string, len, dsPtr);
   535         -#endif
          478  +    return TclUtfToWCharDString(string, len, dsPtr);
   536    479   }
   537    480   
   538    481   char *
   539    482   Tcl_WinTCharToUtf(
   540         -    const TCHAR *string,	/* Source string in Unicode. */
          483  +    const WCHAR *string,	/* Source string in Unicode. */
   541    484       size_t len,			/* Source string length in bytes, or -1
   542    485   				 * for platform-specific string length. */
   543    486       Tcl_DString *dsPtr)		/* Uninitialized or free DString in which the
   544    487   				 * converted string is stored. */
   545    488   {
   546         -#if TCL_UTF_MAX > 4
   547         -    const TCHAR *w, *wEnd;
   548         -    char *p, *result;
   549         -    int oldLength, blen = 1;
   550         -#endif
   551         -
   552    489       Tcl_DStringInit(dsPtr);
   553    490       if (!string) {
   554    491   	return NULL;
   555    492       }
   556    493       if (len == TCL_AUTO_LENGTH) {
   557         -	len = wcslen((TCHAR *)string);
          494  +	len = wcslen((WCHAR *)string);
   558    495       } else {
   559    496   	len /= 2;
   560    497       }
   561         -#if TCL_UTF_MAX > 4
   562         -    oldLength = Tcl_DStringLength(dsPtr);
   563         -    Tcl_DStringSetLength(dsPtr, oldLength + (len + 1) * 4);
   564         -    result = Tcl_DStringValue(dsPtr) + oldLength;
   565         -
   566         -    p = result;
   567         -    wEnd = (TCHAR *)string + len;
   568         -    for (w = (TCHAR *)string; w < wEnd; ) {
   569         -	if (!blen && ((*w & 0xFC00) != 0xDC00)) {
   570         -	    /* Special case for handling high surrogates. */
   571         -	    p += Tcl_UniCharToUtf(-1, p);
   572         -	}
   573         -	blen = Tcl_UniCharToUtf(*w, p);
   574         -	p += blen;
   575         -	if ((*w >= 0xD800) && (blen < 3)) {
   576         -	    /* Indication that high surrogate is handled */
   577         -	    blen = 0;
   578         -	}
   579         -	w++;
   580         -    }
   581         -    if (!blen) {
   582         -	/* Special case for handling high surrogates. */
   583         -	p += Tcl_UniCharToUtf(-1, p);
   584         -    }
   585         -    Tcl_DStringSetLength(dsPtr, oldLength + (p - result));
   586         -
   587         -    return result;
   588         -#else
   589         -    return Tcl_UniCharToUtfDString((Tcl_UniChar *)string, len, dsPtr);
   590         -#endif
          498  +    return TclWCharToUtfDString((unsigned short *)string, len, dsPtr);
   591    499   }
   592    500   
   593    501   /*
   594    502    *------------------------------------------------------------------------
   595    503    *
   596    504    * TclWinCPUID --
   597    505    *

Changes to win/tclWinChan.c.

    92     92   static void		FileSetupProc(ClientData clientData, int flags);
    93     93   static void		FileWatchProc(ClientData instanceData, int mask);
    94     94   static void		FileThreadActionProc(ClientData instanceData,
    95     95   			    int action);
    96     96   static int		FileTruncateProc(ClientData instanceData,
    97     97   			    Tcl_WideInt length);
    98     98   static DWORD		FileGetType(HANDLE handle);
    99         -static int		NativeIsComPort(const TCHAR *nativeName);
           99  +static int		NativeIsComPort(const WCHAR *nativeName);
   100    100   
   101    101   /*
   102    102    * This structure describes the channel type structure for file based IO.
   103    103    */
   104    104   
   105    105   static const Tcl_ChannelType fileChannelType = {
   106    106       "file",			/* Type name. */
................................................................................
   845    845       int mode,			/* POSIX mode. */
   846    846       int permissions)		/* If the open involves creating a file, with
   847    847   				 * what modes to create it? */
   848    848   {
   849    849       Tcl_Channel channel = 0;
   850    850       int channelPermissions = 0;
   851    851       DWORD accessMode = 0, createMode, shareMode, flags;
   852         -    const TCHAR *nativeName;
          852  +    const WCHAR *nativeName;
   853    853       HANDLE handle;
   854    854       char channelName[16 + TCL_INTEGER_SPACE];
   855    855       TclFile readFile = NULL, writeFile = NULL;
   856    856   
   857    857       nativeName = Tcl_FSGetNativePath(pathPtr);
   858    858       if (nativeName == NULL) {
   859    859   	if (interp) {
................................................................................
  1553   1553    *	1 = serial port, 0 = not.
  1554   1554    *
  1555   1555    *----------------------------------------------------------------------
  1556   1556    */
  1557   1557   
  1558   1558   static int
  1559   1559   NativeIsComPort(
  1560         -    const TCHAR *nativePath)	/* Path of file to access, native encoding. */
         1560  +    const WCHAR *nativePath)	/* Path of file to access, native encoding. */
  1561   1561   {
  1562   1562       const WCHAR *p = (const WCHAR *) nativePath;
  1563   1563       int i, len = wcslen(p);
  1564   1564   
  1565   1565       /*
  1566   1566        * 1. Look for com[1-9]:?
  1567   1567        */

Changes to win/tclWinFCmd.c.

    67     67   	{GetWinFileShortName, CannotSetAttribute},
    68     68   	{GetWinFileAttributes, SetWinFileAttributes}};
    69     69   
    70     70   /*
    71     71    * Prototype for the TraverseWinTree callback function.
    72     72    */
    73     73   
    74         -typedef int (TraversalProc)(const TCHAR *srcPtr, const TCHAR *dstPtr,
           74  +typedef int (TraversalProc)(const WCHAR *srcPtr, const WCHAR *dstPtr,
    75     75   	int type, Tcl_DString *errorPtr);
    76     76   
    77     77   /*
    78     78    * Declarations for local functions defined in this file:
    79     79    */
    80     80   
    81     81   static void		StatError(Tcl_Interp *interp, Tcl_Obj *fileName);
    82     82   static int		ConvertFileNameFormat(Tcl_Interp *interp,
    83     83   			    int objIndex, Tcl_Obj *fileName, int longShort,
    84     84   			    Tcl_Obj **attributePtrPtr);
    85         -static int		DoCopyFile(const TCHAR *srcPtr, const TCHAR *dstPtr);
    86         -static int		DoCreateDirectory(const TCHAR *pathPtr);
    87         -static int		DoRemoveJustDirectory(const TCHAR *nativeSrc,
           85  +static int		DoCopyFile(const WCHAR *srcPtr, const WCHAR *dstPtr);
           86  +static int		DoCreateDirectory(const WCHAR *pathPtr);
           87  +static int		DoRemoveJustDirectory(const WCHAR *nativeSrc,
    88     88   			    int ignoreError, Tcl_DString *errorPtr);
    89     89   static int		DoRemoveDirectory(Tcl_DString *pathPtr, int recursive,
    90     90   			    Tcl_DString *errorPtr);
    91         -static int		DoRenameFile(const TCHAR *nativeSrc,
    92         -			    const TCHAR *dstPtr);
    93         -static int		TraversalCopy(const TCHAR *srcPtr, const TCHAR *dstPtr,
           91  +static int		DoRenameFile(const WCHAR *nativeSrc,
           92  +			    const WCHAR *dstPtr);
           93  +static int		TraversalCopy(const WCHAR *srcPtr, const WCHAR *dstPtr,
    94     94   			    int type, Tcl_DString *errorPtr);
    95         -static int		TraversalDelete(const TCHAR *srcPtr,
    96         -			    const TCHAR *dstPtr, int type,
           95  +static int		TraversalDelete(const WCHAR *srcPtr,
           96  +			    const WCHAR *dstPtr, int type,
    97     97   			    Tcl_DString *errorPtr);
    98     98   static int		TraverseWinTree(TraversalProc *traverseProc,
    99     99   			    Tcl_DString *sourcePtr, Tcl_DString *dstPtr,
   100    100   			    Tcl_DString *errorPtr);
   101    101   
   102    102   /*
   103    103    *---------------------------------------------------------------------------
................................................................................
   147    147   {
   148    148       return DoRenameFile(Tcl_FSGetNativePath(srcPathPtr),
   149    149   	    Tcl_FSGetNativePath(destPathPtr));
   150    150   }
   151    151   
   152    152   static int
   153    153   DoRenameFile(
   154         -    const TCHAR *nativeSrc,	/* Pathname of file or dir to be renamed
          154  +    const WCHAR *nativeSrc,	/* Pathname of file or dir to be renamed
   155    155   				 * (native). */
   156         -    const TCHAR *nativeDst)	/* New pathname for file or directory
          156  +    const WCHAR *nativeDst)	/* New pathname for file or directory
   157    157   				 * (native). */
   158    158   {
   159    159   #if defined(HAVE_NO_SEH) && !defined(_WIN64)
   160    160       TCLEXCEPTION_REGISTRATION registration;
   161    161   #endif
   162    162       DWORD srcAttr, dstAttr;
   163    163       int retval = -1;
................................................................................
   303    303       if (errno == EBADF) {
   304    304   	errno = EACCES;
   305    305   	return TCL_ERROR;
   306    306       }
   307    307       if (errno == EACCES) {
   308    308       decode:
   309    309   	if (srcAttr & FILE_ATTRIBUTE_DIRECTORY) {
   310         -	    TCHAR *nativeSrcRest, *nativeDstRest;
          310  +	    WCHAR *nativeSrcRest, *nativeDstRest;
   311    311   	    const char **srcArgv, **dstArgv;
   312    312   	    int size, srcArgc, dstArgc;
   313         -	    TCHAR nativeSrcPath[MAX_PATH];
   314         -	    TCHAR nativeDstPath[MAX_PATH];
          313  +	    WCHAR nativeSrcPath[MAX_PATH];
          314  +	    WCHAR nativeDstPath[MAX_PATH];
   315    315   	    Tcl_DString srcString, dstString;
   316    316   	    const char *src, *dst;
   317    317   
   318    318   	    size = GetFullPathName(nativeSrc, MAX_PATH,
   319    319   		    nativeSrcPath, &nativeSrcRest);
   320    320   	    if ((size == 0) || (size > MAX_PATH)) {
   321    321   		return TCL_ERROR;
................................................................................
   372    372   		 * The MoveFile system call already handles the case of moving
   373    373   		 * a file between filesystems.
   374    374   		 */
   375    375   
   376    376   		Tcl_SetErrno(EXDEV);
   377    377   	    }
   378    378   
   379         -	    Tcl_Free(srcArgv);
   380         -	    Tcl_Free(dstArgv);
          379  +	    Tcl_Free((void *)srcArgv);
          380  +	    Tcl_Free((void *)dstArgv);
   381    381   	}
   382    382   
   383    383   	/*
   384    384   	 * Other types of access failure is that dst is a read-only
   385    385   	 * filesystem, that an open file referred to src or dest, or that src
   386    386   	 * or dest specified the current working directory on the current
   387    387   	 * filesystem. EACCES is returned for those cases.
................................................................................
   441    441   		 *
   442    442   		 * 1. Rename existing file to temp name.
   443    443   		 * 2. Rename old file to new name.
   444    444   		 * 3. If success, delete temp file. If failure, put temp file
   445    445   		 *    back to old name.
   446    446   		 */
   447    447   
   448         -		TCHAR *nativeRest, *nativeTmp, *nativePrefix;
          448  +		WCHAR *nativeRest, *nativeTmp, *nativePrefix;
   449    449   		int result, size;
   450         -		TCHAR tempBuf[MAX_PATH];
          450  +		WCHAR tempBuf[MAX_PATH];
   451    451   
   452    452   		size = GetFullPathName(nativeDst, MAX_PATH,
   453    453   			tempBuf, &nativeRest);
   454    454   		if ((size == 0) || (size > MAX_PATH) || (nativeRest == NULL)) {
   455    455   		    return TCL_ERROR;
   456    456   		}
   457         -		nativeTmp = (TCHAR *) tempBuf;
          457  +		nativeTmp = (WCHAR *) tempBuf;
   458    458   		nativeRest[0] = L'\0';
   459    459   
   460    460   		result = TCL_ERROR;
   461         -		nativePrefix = (TCHAR *) L"tclr";
          461  +		nativePrefix = (WCHAR *) L"tclr";
   462    462   		if (GetTempFileName(nativeTmp, nativePrefix,
   463    463   			0, tempBuf) != 0) {
   464    464   		    /*
   465    465   		     * Strictly speaking, need the following DeleteFile and
   466    466   		     * MoveFile to be joined as an atomic operation so no
   467    467   		     * other app comes along in the meantime and creates the
   468    468   		     * same temp file.
................................................................................
   536    536   {
   537    537       return DoCopyFile(Tcl_FSGetNativePath(srcPathPtr),
   538    538   	    Tcl_FSGetNativePath(destPathPtr));
   539    539   }
   540    540   
   541    541   static int
   542    542   DoCopyFile(
   543         -    const TCHAR *nativeSrc,	/* Pathname of file to be copied (native). */
   544         -    const TCHAR *nativeDst)	/* Pathname of file to copy to (native). */
          543  +    const WCHAR *nativeSrc,	/* Pathname of file to be copied (native). */
          544  +    const WCHAR *nativeDst)	/* Pathname of file to copy to (native). */
   545    545   {
   546    546   #if defined(HAVE_NO_SEH) && !defined(_WIN64)
   547    547       TCLEXCEPTION_REGISTRATION registration;
   548    548   #endif
   549    549       int retval = -1;
   550    550   
   551    551       /*
................................................................................
   745    745   }
   746    746   
   747    747   int
   748    748   TclpDeleteFile(
   749    749       const void *nativePath)	/* Pathname of file to be removed (native). */
   750    750   {
   751    751       DWORD attr;
   752         -    const TCHAR *path = nativePath;
          752  +    const WCHAR *path = nativePath;
   753    753   
   754    754       /*
   755    755        * The DeleteFile API acts differently under Win95/98 and NT WRT NULL and
   756    756        * "". Avoid passing these values.
   757    757        */
   758    758   
   759    759       if (path == NULL || path[0] == '\0') {
................................................................................
   855    855       Tcl_Obj *pathPtr)
   856    856   {
   857    857       return DoCreateDirectory(Tcl_FSGetNativePath(pathPtr));
   858    858   }
   859    859   
   860    860   static int
   861    861   DoCreateDirectory(
   862         -    const TCHAR *nativePath)	/* Pathname of directory to create (native). */
          862  +    const WCHAR *nativePath)	/* Pathname of directory to create (native). */
   863    863   {
   864    864       if (CreateDirectory(nativePath, NULL) == 0) {
   865    865   	DWORD error = GetLastError();
   866    866   
   867    867   	TclWinConvertError(error);
   868    868   	return TCL_ERROR;
   869    869       }
................................................................................
  1005   1005       }
  1006   1006   
  1007   1007       return ret;
  1008   1008   }
  1009   1009   
  1010   1010   static int
  1011   1011   DoRemoveJustDirectory(
  1012         -    const TCHAR *nativePath,	/* Pathname of directory to be removed
         1012  +    const WCHAR *nativePath,	/* Pathname of directory to be removed
  1013   1013   				 * (native). */
  1014   1014       int ignoreError,		/* If non-zero, don't initialize the errorPtr
  1015   1015   				 * under some circumstances on return. */
  1016   1016       Tcl_DString *errorPtr)	/* If non-NULL, uninitialized or free DString
  1017   1017   				 * filled with UTF-8 name of file causing
  1018   1018   				 * error. */
  1019   1019   {
................................................................................
  1125   1125       int recursive,		/* If non-zero, removes directories that are
  1126   1126   				 * nonempty. Otherwise, will only remove empty
  1127   1127   				 * directories. */
  1128   1128       Tcl_DString *errorPtr)	/* If non-NULL, uninitialized or free DString
  1129   1129   				 * filled with UTF-8 name of file causing
  1130   1130   				 * error. */
  1131   1131   {
  1132         -    int res = DoRemoveJustDirectory((const TCHAR *)Tcl_DStringValue(pathPtr), recursive,
         1132  +    int res = DoRemoveJustDirectory((const WCHAR *)Tcl_DStringValue(pathPtr), recursive,
  1133   1133   	    errorPtr);
  1134   1134   
  1135   1135       if ((res == TCL_ERROR) && (recursive != 0) && (Tcl_GetErrno() == EEXIST)) {
  1136   1136   	/*
  1137   1137   	 * The directory is nonempty, but the recursive flag has been
  1138   1138   	 * specified, so we recursively remove all the files in the directory.
  1139   1139   	 */
................................................................................
  1176   1176   				 * parallel with source directory (native),
  1177   1177   				 * may be NULL. */
  1178   1178       Tcl_DString *errorPtr)	/* If non-NULL, uninitialized or free DString
  1179   1179   				 * filled with UTF-8 name of file causing
  1180   1180   				 * error. */
  1181   1181   {
  1182   1182       DWORD sourceAttr;
  1183         -    TCHAR *nativeSource, *nativeTarget, *nativeErrfile;
         1183  +    WCHAR *nativeSource, *nativeTarget, *nativeErrfile;
  1184   1184       int result, found, sourceLen, targetLen = 0, oldSourceLen, oldTargetLen;
  1185   1185       HANDLE handle;
  1186   1186       WIN32_FIND_DATA data;
  1187   1187   
  1188   1188       nativeErrfile = NULL;
  1189   1189       result = TCL_OK;
  1190   1190       oldTargetLen = 0;		/* lint. */
  1191   1191   
  1192         -    nativeSource = (TCHAR *) Tcl_DStringValue(sourcePtr);
  1193         -    nativeTarget = (TCHAR *)
         1192  +    nativeSource = (WCHAR *) Tcl_DStringValue(sourcePtr);
         1193  +    nativeTarget = (WCHAR *)
  1194   1194   	    (targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr));
  1195   1195   
  1196   1196       oldSourceLen = Tcl_DStringLength(sourcePtr);
  1197   1197       sourceAttr = GetFileAttributes(nativeSource);
  1198   1198       if (sourceAttr == 0xffffffff) {
  1199   1199   	nativeErrfile = nativeSource;
  1200   1200   	goto end;
................................................................................
  1213   1213   	/*
  1214   1214   	 * Process the regular file
  1215   1215   	 */
  1216   1216   
  1217   1217   	return traverseProc(nativeSource, nativeTarget, DOTREE_F, errorPtr);
  1218   1218       }
  1219   1219   
  1220         -    Tcl_DStringAppend(sourcePtr, (char *) TEXT("\\*.*"), 4 * sizeof(TCHAR) + 1);
         1220  +    Tcl_DStringAppend(sourcePtr, (char *) L"\\*.*", 4 * sizeof(WCHAR) + 1);
  1221   1221       Tcl_DStringSetLength(sourcePtr, Tcl_DStringLength(sourcePtr) - 1);
  1222   1222   
  1223         -    nativeSource = (TCHAR *) Tcl_DStringValue(sourcePtr);
         1223  +    nativeSource = (WCHAR *) Tcl_DStringValue(sourcePtr);
  1224   1224       handle = FindFirstFile(nativeSource, &data);
  1225   1225       if (handle == INVALID_HANDLE_VALUE) {
  1226   1226   	/*
  1227   1227   	 * Can't read directory.
  1228   1228   	 */
  1229   1229   
  1230   1230   	TclWinConvertError(GetLastError());
................................................................................
  1237   1237       result = traverseProc(nativeSource, nativeTarget, DOTREE_PRED,
  1238   1238   	    errorPtr);
  1239   1239       if (result != TCL_OK) {
  1240   1240   	FindClose(handle);
  1241   1241   	return result;
  1242   1242       }
  1243   1243   
  1244         -    sourceLen = oldSourceLen + sizeof(TCHAR);
  1245         -    Tcl_DStringAppend(sourcePtr, (char *) TEXT("\\"), sizeof(TCHAR) + 1);
         1244  +    sourceLen = oldSourceLen + sizeof(WCHAR);
         1245  +    Tcl_DStringAppend(sourcePtr, (char *) L"\\", sizeof(WCHAR) + 1);
  1246   1246       Tcl_DStringSetLength(sourcePtr, sourceLen);
  1247   1247       if (targetPtr != NULL) {
  1248   1248   	oldTargetLen = Tcl_DStringLength(targetPtr);
  1249   1249   
  1250   1250   	targetLen = oldTargetLen;
  1251         -	targetLen += sizeof(TCHAR);
  1252         -	Tcl_DStringAppend(targetPtr, (char *) TEXT("\\"), sizeof(TCHAR) + 1);
         1251  +	targetLen += sizeof(WCHAR);
         1252  +	Tcl_DStringAppend(targetPtr, (char *) L"\\", sizeof(WCHAR) + 1);
  1253   1253   	Tcl_DStringSetLength(targetPtr, targetLen);
  1254   1254       }
  1255   1255   
  1256   1256       found = 1;
  1257   1257       for (; found; found = FindNextFile(handle, &data)) {
  1258         -	TCHAR *nativeName;
         1258  +	WCHAR *nativeName;
  1259   1259   	int len;
  1260   1260   
  1261         -	TCHAR *wp = data.cFileName;
         1261  +	WCHAR *wp = data.cFileName;
  1262   1262   	if (*wp == '.') {
  1263   1263   	    wp++;
  1264   1264   	    if (*wp == '.') {
  1265   1265   		wp++;
  1266   1266   	    }
  1267   1267   	    if (*wp == '\0') {
  1268   1268   		continue;
  1269   1269   	    }
  1270   1270   	}
  1271         -	nativeName = (TCHAR *) data.cFileName;
  1272         -	len = _tcslen(data.cFileName) * sizeof(TCHAR);
         1271  +	nativeName = (WCHAR *) data.cFileName;
         1272  +	len = wcslen(data.cFileName) * sizeof(WCHAR);
  1273   1273   
  1274   1274   	/*
  1275   1275   	 * Append name after slash, and recurse on the file.
  1276   1276   	 */
  1277   1277   
  1278   1278   	Tcl_DStringAppend(sourcePtr, (char *) nativeName, len + 1);
  1279   1279   	Tcl_DStringSetLength(sourcePtr, Tcl_DStringLength(sourcePtr) - 1);
................................................................................
  1310   1310       }
  1311   1311       if (result == TCL_OK) {
  1312   1312   	/*
  1313   1313   	 * Call traverseProc() on a directory after visiting all the
  1314   1314   	 * files in that directory.
  1315   1315   	 */
  1316   1316   
  1317         -	result = traverseProc((const TCHAR *)Tcl_DStringValue(sourcePtr),
  1318         -		(const TCHAR *)(targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr)),
         1317  +	result = traverseProc((const WCHAR *)Tcl_DStringValue(sourcePtr),
         1318  +		(const WCHAR *)(targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr)),
  1319   1319   		DOTREE_POSTD, errorPtr);
  1320   1320       }
  1321   1321   
  1322   1322     end:
  1323   1323       if (nativeErrfile != NULL) {
  1324   1324   	TclWinConvertError(GetLastError());
  1325   1325   	if (errorPtr != NULL) {
................................................................................
  1346   1346    *	Depending on the value of type, src may be copied to dst.
  1347   1347    *
  1348   1348    *----------------------------------------------------------------------
  1349   1349    */
  1350   1350   
  1351   1351   static int
  1352   1352   TraversalCopy(
  1353         -    const TCHAR *nativeSrc,	/* Source pathname to copy. */
  1354         -    const TCHAR *nativeDst,	/* Destination pathname of copy. */
         1353  +    const WCHAR *nativeSrc,	/* Source pathname to copy. */
         1354  +    const WCHAR *nativeDst,	/* Destination pathname of copy. */
  1355   1355       int type,			/* Reason for call - see TraverseWinTree() */
  1356   1356       Tcl_DString *errorPtr)	/* If non-NULL, initialized DString filled
  1357   1357   				 * with UTF-8 name of file causing error. */
  1358   1358   {
  1359   1359       switch (type) {
  1360   1360       case DOTREE_F:
  1361   1361   	if (DoCopyFile(nativeSrc, nativeDst) == TCL_OK) {
................................................................................
  1412   1412    *	set accordingly.
  1413   1413    *
  1414   1414    *----------------------------------------------------------------------
  1415   1415    */
  1416   1416   
  1417   1417   static int
  1418   1418   TraversalDelete(
  1419         -    const TCHAR *nativeSrc,	/* Source pathname to delete. */
  1420         -    const TCHAR *dstPtr,	/* Not used. */
         1419  +    const WCHAR *nativeSrc,	/* Source pathname to delete. */
         1420  +    const WCHAR *dstPtr,	/* Not used. */
  1421   1421       int type,			/* Reason for call - see TraverseWinTree() */
  1422   1422       Tcl_DString *errorPtr)	/* If non-NULL, initialized DString filled
  1423   1423   				 * with UTF-8 name of file causing error. */
  1424   1424   {
  1425   1425       switch (type) {
  1426   1426       case DOTREE_F:
  1427   1427   	if (TclpDeleteFile(nativeSrc) == TCL_OK) {
................................................................................
  1499   1499   GetWinFileAttributes(
  1500   1500       Tcl_Interp *interp,		/* The interp we are using for errors. */
  1501   1501       int objIndex,		/* The index of the attribute. */
  1502   1502       Tcl_Obj *fileName,		/* The name of the file. */
  1503   1503       Tcl_Obj **attributePtrPtr)	/* A pointer to return the object with. */
  1504   1504   {
  1505   1505       DWORD result;
  1506         -    const TCHAR *nativeName;
         1506  +    const WCHAR *nativeName;
  1507   1507       int attr;
  1508   1508   
  1509   1509       nativeName = Tcl_FSGetNativePath(fileName);
  1510   1510       result = GetFileAttributes(nativeName);
  1511   1511   
  1512   1512       if (result == 0xffffffff) {
  1513   1513   	StatError(interp, fileName);
................................................................................
  1632   1632   	     */
  1633   1633   
  1634   1634   	    pathv[0] = (char) Tcl_UniCharToUpper(UCHAR(pathv[0]));
  1635   1635   	} else {
  1636   1636   	    Tcl_Obj *tempPath;
  1637   1637   	    Tcl_DString ds;
  1638   1638   	    Tcl_DString dsTemp;
  1639         -	    const TCHAR *nativeName;
         1639  +	    const WCHAR *nativeName;
  1640   1640   	    const char *tempString;
  1641   1641   	    WIN32_FIND_DATA data;
  1642   1642   	    HANDLE handle;
  1643   1643   	    DWORD attr;
  1644   1644   
  1645   1645   	    tempPath = Tcl_FSJoinPath(splitPath, i+1);
  1646   1646   	    Tcl_IncrRefCount(tempPath);
................................................................................
  1679   1679   	    nativeName = data.cAlternateFileName;
  1680   1680   	    if (longShort) {
  1681   1681   		if (data.cFileName[0] != '\0') {
  1682   1682   		    nativeName = data.cFileName;
  1683   1683   		}
  1684   1684   	    } else {
  1685   1685   		if (data.cAlternateFileName[0] == '\0') {
  1686         -		    nativeName = (TCHAR *) data.cFileName;
         1686  +		    nativeName = (WCHAR *) data.cFileName;
  1687   1687   		}
  1688   1688   	    }
  1689   1689   
  1690   1690   	    /*
  1691   1691   	     * Purify reports a extraneous UMR in Tcl_WinTCharToUtf() trying
  1692   1692   	     * to dereference nativeName as a Unicode string. I have proven to
  1693   1693   	     * myself that purify is wrong by running the following example
................................................................................
  1825   1825       Tcl_Interp *interp,		/* The interp we are using for errors. */
  1826   1826       int objIndex,		/* The index of the attribute. */
  1827   1827       Tcl_Obj *fileName,		/* The name of the file. */
  1828   1828       Tcl_Obj *attributePtr)	/* The new value of the attribute. */
  1829   1829   {
  1830   1830       DWORD fileAttributes, old;
  1831   1831       int yesNo, result;
  1832         -    const TCHAR *nativeName;
         1832  +    const WCHAR *nativeName;
  1833   1833   
  1834   1834       nativeName = Tcl_FSGetNativePath(fileName);
  1835   1835       fileAttributes = old = GetFileAttributes(nativeName);
  1836   1836   
  1837   1837       if (fileAttributes == 0xffffffff) {
  1838   1838   	StatError(interp, fileName);
  1839   1839   	return TCL_ERROR;

Changes to win/tclWinFile.c.

   152    152   static time_t		ToCTime(FILETIME fileTime);
   153    153   static void		FromCTime(time_t posixTime, FILETIME *fileTime);
   154    154   
   155    155   /*
   156    156    * Declarations for local functions defined in this file:
   157    157    */
   158    158   
   159         -static int		NativeAccess(const TCHAR *path, int mode);
   160         -static int		NativeDev(const TCHAR *path);
   161         -static int		NativeStat(const TCHAR *path, Tcl_StatBuf *statPtr,
          159  +static int		NativeAccess(const WCHAR *path, int mode);
          160  +static int		NativeDev(const WCHAR *path);
          161  +static int		NativeStat(const WCHAR *path, Tcl_StatBuf *statPtr,
   162    162   			    int checkLinks);
   163    163   static unsigned short	NativeStatMode(DWORD attr, int checkLinks,
   164    164   			    int isExec);
   165         -static int		NativeIsExec(const TCHAR *path);
   166         -static int		NativeReadReparse(const TCHAR *LinkDirectory,
          165  +static int		NativeIsExec(const WCHAR *path);
          166  +static int		NativeReadReparse(const WCHAR *LinkDirectory,
   167    167   			    REPARSE_DATA_BUFFER *buffer, DWORD desiredAccess);
   168         -static int		NativeWriteReparse(const TCHAR *LinkDirectory,
          168  +static int		NativeWriteReparse(const WCHAR *LinkDirectory,
   169    169   			    REPARSE_DATA_BUFFER *buffer);
   170    170   static int		NativeMatchType(int isDrive, DWORD attr,
   171         -			    const TCHAR *nativeName, Tcl_GlobTypeData *types);
          171  +			    const WCHAR *nativeName, Tcl_GlobTypeData *types);
   172    172   static int		WinIsDrive(const char *name, size_t nameLen);
   173    173   static int		WinIsReserved(const char *path);
   174         -static Tcl_Obj *	WinReadLink(const TCHAR *LinkSource);
   175         -static Tcl_Obj *	WinReadLinkDirectory(const TCHAR *LinkDirectory);
   176         -static int		WinLink(const TCHAR *LinkSource,
   177         -			    const TCHAR *LinkTarget, int linkAction);
   178         -static int		WinSymLinkDirectory(const TCHAR *LinkDirectory,
   179         -			    const TCHAR *LinkTarget);
          174  +static Tcl_Obj *	WinReadLink(const WCHAR *LinkSource);
          175  +static Tcl_Obj *	WinReadLinkDirectory(const WCHAR *LinkDirectory);
          176  +static int		WinLink(const WCHAR *LinkSource,
          177  +			    const WCHAR *LinkTarget, int linkAction);
          178  +static int		WinSymLinkDirectory(const WCHAR *LinkDirectory,
          179  +			    const WCHAR *LinkTarget);
   180    180   MODULE_SCOPE void	tclWinDebugPanic(const char *format, ...);
   181    181   
   182    182   /*
   183    183    *--------------------------------------------------------------------
   184    184    *
   185    185    * WinLink --
   186    186    *
................................................................................
   187    187    *	Make a link from source to target.
   188    188    *
   189    189    *--------------------------------------------------------------------
   190    190    */
   191    191   
   192    192   static int
   193    193   WinLink(
   194         -    const TCHAR *linkSourcePath,
   195         -    const TCHAR *linkTargetPath,
          194  +    const WCHAR *linkSourcePath,
          195  +    const WCHAR *linkTargetPath,
   196    196       int linkAction)
   197    197   {
   198         -    TCHAR tempFileName[MAX_PATH];
   199         -    TCHAR *tempFilePart;
          198  +    WCHAR tempFileName[MAX_PATH];
          199  +    WCHAR *tempFilePart;
   200    200       DWORD attr;
   201    201   
   202    202       /*
   203    203        * Get the full path referenced by the target.
   204    204        */
   205    205   
   206    206       if (!GetFullPathName(linkTargetPath, MAX_PATH, tempFileName,
................................................................................
   302    302    *	What does 'LinkSource' point to?
   303    303    *
   304    304    *--------------------------------------------------------------------
   305    305    */
   306    306   
   307    307   static Tcl_Obj *
   308    308   WinReadLink(
   309         -    const TCHAR *linkSourcePath)
          309  +    const WCHAR *linkSourcePath)
   310    310   {
   311         -    TCHAR tempFileName[MAX_PATH];
   312         -    TCHAR *tempFilePart;
          311  +    WCHAR tempFileName[MAX_PATH];
          312  +    WCHAR *tempFilePart;
   313    313       DWORD attr;
   314    314   
   315    315       /*
   316    316        * Get the full path referenced by the target.
   317    317        */
   318    318   
   319    319       if (!GetFullPathName(linkSourcePath, MAX_PATH, tempFileName,
................................................................................
   366    366    *	Zero on success.
   367    367    *
   368    368    *--------------------------------------------------------------------
   369    369    */
   370    370   
   371    371   static int
   372    372   WinSymLinkDirectory(
   373         -    const TCHAR *linkDirPath,
   374         -    const TCHAR *linkTargetPath)
          373  +    const WCHAR *linkDirPath,
          374  +    const WCHAR *linkTargetPath)
   375    375   {
   376    376       DUMMY_REPARSE_BUFFER dummy;
   377    377       REPARSE_DATA_BUFFER *reparseBuffer = (REPARSE_DATA_BUFFER *) &dummy;
   378    378       int len;
   379    379       WCHAR nativeTarget[MAX_PATH];
   380    380       WCHAR *loop;
   381    381   
................................................................................
   438    438    *	Zero on success.
   439    439    *
   440    440    *--------------------------------------------------------------------
   441    441    */
   442    442   
   443    443   int
   444    444   TclWinSymLinkCopyDirectory(
   445         -    const TCHAR *linkOrigPath,	/* Existing junction - reparse point */
   446         -    const TCHAR *linkCopyPath)	/* Will become a duplicate junction */
          445  +    const WCHAR *linkOrigPath,	/* Existing junction - reparse point */
          446  +    const WCHAR *linkCopyPath)	/* Will become a duplicate junction */
   447    447   {
   448    448       DUMMY_REPARSE_BUFFER dummy;
   449    449       REPARSE_DATA_BUFFER *reparseBuffer = (REPARSE_DATA_BUFFER *) &dummy;
   450    450   
   451    451       if (NativeReadReparse(linkOrigPath, reparseBuffer, GENERIC_READ)) {
   452    452   	return -1;
   453    453       }
................................................................................
   469    469    *	Zero on success.
   470    470    *
   471    471    *--------------------------------------------------------------------
   472    472    */
   473    473   
   474    474   int
   475    475   TclWinSymLinkDelete(
   476         -    const TCHAR *linkOrigPath,
          476  +    const WCHAR *linkOrigPath,
   477    477       int linkOnly)
   478    478   {
   479    479       /*
   480    480        * It is a symbolic link - remove it.
   481    481        */
   482    482   
   483    483       DUMMY_REPARSE_BUFFER dummy;
................................................................................
   534    534   #if defined (__clang__) || ((__GNUC__)  && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
   535    535   #pragma GCC diagnostic push
   536    536   #pragma GCC diagnostic ignored "-Warray-bounds"
   537    537   #endif
   538    538   
   539    539   static Tcl_Obj *
   540    540   WinReadLinkDirectory(
   541         -    const TCHAR *linkDirPath)
          541  +    const WCHAR *linkDirPath)
   542    542   {
   543    543       int attr, len, offset;
   544    544       DUMMY_REPARSE_BUFFER dummy;
   545    545       REPARSE_DATA_BUFFER *reparseBuffer = (REPARSE_DATA_BUFFER *) &dummy;
   546    546       Tcl_Obj *retVal;
   547    547       Tcl_DString ds;
   548    548       const char *copy;
................................................................................
   630    630   		 * Strip off the prefix.
   631    631   		 */
   632    632   
   633    633   		offset = 4;
   634    634   	    }
   635    635   	}
   636    636   
   637         -	Tcl_WinTCharToUtf((const TCHAR *)
          637  +	Tcl_WinTCharToUtf(
   638    638   		reparseBuffer->MountPointReparseBuffer.PathBuffer,
   639         -		(int) reparseBuffer->MountPointReparseBuffer
          639  +		reparseBuffer->MountPointReparseBuffer
   640    640   		.SubstituteNameLength, &ds);
   641    641   
   642    642   	copy = Tcl_DStringValue(&ds)+offset;
   643    643   	len = Tcl_DStringLength(&ds)-offset;
   644    644   	retVal = Tcl_NewStringObj(copy,len);
   645    645   	Tcl_IncrRefCount(retVal);
   646    646   	Tcl_DStringFree(&ds);
................................................................................
   669    669    *	Zero on success.
   670    670    *
   671    671    *--------------------------------------------------------------------
   672    672    */
   673    673   
   674    674   static int
   675    675   NativeReadReparse(
   676         -    const TCHAR *linkDirPath,	/* The junction to read */
          676  +    const WCHAR *linkDirPath,	/* The junction to read */
   677    677       REPARSE_DATA_BUFFER *buffer,/* Pointer to buffer. Cannot be NULL */
   678    678       DWORD desiredAccess)
   679    679   {
   680    680       HANDLE hFile;
   681    681       DWORD returnedLength;
   682    682   
   683    683       hFile = CreateFile(linkDirPath, desiredAccess, FILE_SHARE_READ, NULL, OPEN_EXISTING,
................................................................................
   725    725    *	Assumption that LinkDirectory does not exist.
   726    726    *
   727    727    *--------------------------------------------------------------------
   728    728    */
   729    729   
   730    730   static int
   731    731   NativeWriteReparse(
   732         -    const TCHAR *linkDirPath,
          732  +    const WCHAR *linkDirPath,
   733    733       REPARSE_DATA_BUFFER *buffer)
   734    734   {
   735    735       HANDLE hFile;
   736    736       DWORD returnedLength;
   737    737   
   738    738       /*
   739    739        * Create the directory - it must not already exist.
................................................................................
   889    889       Tcl_Obj *resultPtr,		/* List object to lappend results. */
   890    890       Tcl_Obj *pathPtr,		/* Contains path to directory to search. */
   891    891       const char *pattern,	/* Pattern to match against. */
   892    892       Tcl_GlobTypeData *types)	/* Object containing list of acceptable types.
   893    893   				 * May be NULL. In particular the directory
   894    894   				 * flag is very important. */
   895    895   {
   896         -    const TCHAR *native;
          896  +    const WCHAR *native;
   897    897   
   898    898       if (types != NULL && types->type == TCL_GLOB_TYPE_MOUNT) {
   899    899   	/*
   900    900   	 * The native filesystem never adds mounts.
   901    901   	 */
   902    902   
   903    903   	return TCL_OK;
................................................................................
   909    909   	if (norm != NULL) {
   910    910   	    /*
   911    911   	     * Match a single file directly.
   912    912   	     */
   913    913   
   914    914   	    DWORD attr;
   915    915   	    WIN32_FILE_ATTRIBUTE_DATA data;
   916         -	    size_t length;
          916  +	    size_t length = 0;
   917    917   	    const char *str = TclGetStringFromObj(norm, &length);
   918    918   
   919    919   	    native = Tcl_FSGetNativePath(pathPtr);
   920    920   
   921    921   	    if (GetFileAttributesEx(native,
   922    922   		    GetFileExInfoStandard, &data) != TRUE) {
   923    923   		return TCL_OK;
................................................................................
  1289   1289    */
  1290   1290   
  1291   1291   static int
  1292   1292   NativeMatchType(
  1293   1293       int isDrive,		/* Is this a drive. */
  1294   1294       DWORD attr,			/* We already know the attributes for the
  1295   1295   				 * file. */
  1296         -    const TCHAR *nativeName,	/* Native path to check. */
         1296  +    const WCHAR *nativeName,	/* Native path to check. */
  1297   1297       Tcl_GlobTypeData *types)	/* Type description to match against. */
  1298   1298   {
  1299   1299       /*
  1300   1300        * 'attr' represents the attributes of the file, but we only want to
  1301   1301        * retrieve this info if it is absolutely necessary because it is an
  1302   1302        * expensive call. Unfortunately, to deal with hidden files properly, we
  1303   1303        * must always retrieve it.
................................................................................
  1441   1441   		rc = 1;
  1442   1442   		result = Tcl_DStringValue(bufferPtr);
  1443   1443   	    }
  1444   1444   	}
  1445   1445   	Tcl_DStringFree(&ds);
  1446   1446       } else {
  1447   1447   	Tcl_DStringInit(&ds);
  1448         -	wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds);
         1448  +	wName = TclUtfToWCharDString(domain + 1, -1, &ds);
  1449   1449   	rc = NetGetDCName(NULL, wName, (LPBYTE *) &wDomain);
  1450   1450   	Tcl_DStringFree(&ds);
  1451   1451   	nameLen = domain - name;
  1452   1452       }
  1453   1453       if (rc == 0) {
  1454   1454   	Tcl_DStringInit(&ds);
  1455         -	wName = Tcl_UtfToUniCharDString(name, nameLen, &ds);
         1455  +	wName = TclUtfToWCharDString(name, nameLen, &ds);
  1456   1456   	while (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) &uiPtr) != 0) {
  1457   1457   	    /*
  1458   1458   	     * user does not exists - if domain was not specified,
  1459   1459   	     * try again using current domain.
  1460   1460   	     */
  1461   1461   	    rc = 1;
  1462   1462   	    if (domain != NULL) break;
................................................................................
  1466   1466   	    domain = INT2PTR(-1); /* repeat once */
  1467   1467   	}
  1468   1468   	if (rc == 0) {
  1469   1469   	    DWORD i, size = MAX_PATH;
  1470   1470   	    wHomeDir = uiPtr->usri1_home_dir;
  1471   1471   	    if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) {
  1472   1472   		size = lstrlenW(wHomeDir);
  1473         -		Tcl_UniCharToUtfDString(wHomeDir, size, bufferPtr);
         1473  +		TclWCharToUtfDString(wHomeDir, size, bufferPtr);
  1474   1474   	    } else {
  1475   1475   		/*
  1476   1476   		 * User exists but has no home dir. Return
  1477   1477   		 * "{GetProfilesDirectory}/<user>".
  1478   1478   		 */
  1479   1479   		GetProfilesDirectoryW(buf, &size);
  1480         -		Tcl_UniCharToUtfDString(buf, size-1, bufferPtr);
         1480  +		TclWCharToUtfDString(buf, size-1, bufferPtr);
  1481   1481   		Tcl_DStringAppend(bufferPtr, "/", 1);
  1482   1482   		Tcl_DStringAppend(bufferPtr, name, nameLen);
  1483   1483   	    }
  1484   1484   	    result = Tcl_DStringValue(bufferPtr);
  1485         -	    /* be sure we returns normalized path */
         1485  +	    /* be sure we return normalized path */
  1486   1486   	    for (i = 0; i < size; ++i){
  1487   1487   		if (result[i] == '\\') result[i] = '/';
  1488   1488   	    }
  1489   1489   	    NetApiBufferFree((void *) uiPtr);
  1490   1490   	}
  1491   1491   	Tcl_DStringFree(&ds);
  1492   1492       }
................................................................................
  1538   1538    *	See access documentation.
  1539   1539    *
  1540   1540    *---------------------------------------------------------------------------
  1541   1541    */
  1542   1542   
  1543   1543   static int
  1544   1544   NativeAccess(
  1545         -    const TCHAR *nativePath,	/* Path of file to access, native encoding. */
         1545  +    const WCHAR *nativePath,	/* Path of file to access, native encoding. */
  1546   1546       int mode)			/* Permission setting. */
  1547   1547   {
  1548   1548       DWORD attr;
  1549   1549   
  1550   1550       attr = GetFileAttributes(nativePath);
  1551   1551   
  1552   1552       if (attr == INVALID_FILE_ATTRIBUTES) {
................................................................................
  1800   1800    *	1 = executable, 0 = not.
  1801   1801    *
  1802   1802    *----------------------------------------------------------------------
  1803   1803    */
  1804   1804   
  1805   1805   static int
  1806   1806   NativeIsExec(
  1807         -    const TCHAR *path)
         1807  +    const WCHAR *path)
  1808   1808   {
  1809         -    int len = _tcslen(path);
         1809  +    int len = wcslen(path);
  1810   1810   
  1811   1811       if (len < 5) {
  1812   1812   	return 0;
  1813   1813       }
  1814   1814   
  1815   1815       if (path[len-4] != '.') {
  1816   1816   	return 0;
  1817   1817       }
  1818   1818   
  1819   1819       path += len-3;
  1820         -    if ((_tcsicmp(path, TEXT("exe")) == 0)
  1821         -	    || (_tcsicmp(path, TEXT("com")) == 0)
  1822         -	    || (_tcsicmp(path, TEXT("cmd")) == 0)
  1823         -	    || (_tcsicmp(path, TEXT("cmd")) == 0)
  1824         -	    || (_tcsicmp(path, TEXT("bat")) == 0)) {
         1820  +    if ((wcsicmp(path, L"exe") == 0)
         1821  +	    || (wcsicmp(path, L"com") == 0)
         1822  +	    || (wcsicmp(path, L"cmd") == 0)
         1823  +	    || (wcsicmp(path, L"cmd") == 0)
         1824  +	    || (wcsicmp(path, L"bat") == 0)) {
  1825   1825   	return 1;
  1826   1826       }
  1827   1827       return 0;
  1828   1828   }
  1829   1829   
  1830   1830   /*
  1831   1831    *----------------------------------------------------------------------
................................................................................
  1844   1844    */
  1845   1845   
  1846   1846   int
  1847   1847   TclpObjChdir(
  1848   1848       Tcl_Obj *pathPtr)	/* Path to new working directory. */
  1849   1849   {
  1850   1850       int result;
  1851         -    const TCHAR *nativePath;
         1851  +    const WCHAR *nativePath;
  1852   1852   
  1853   1853       nativePath = Tcl_FSGetNativePath(pathPtr);
  1854   1854   
  1855   1855       if (!nativePath) {
  1856   1856   	return -1;
  1857   1857       }
  1858   1858       result = SetCurrentDirectory(nativePath);
................................................................................
  1888   1888   
  1889   1889   const char *
  1890   1890   TclpGetCwd(
  1891   1891       Tcl_Interp *interp,		/* If non-NULL, used for error reporting. */
  1892   1892       Tcl_DString *bufferPtr)	/* Uninitialized or free DString filled with
  1893   1893   				 * name of current directory. */
  1894   1894   {
  1895         -    TCHAR buffer[MAX_PATH];
         1895  +    WCHAR buffer[MAX_PATH];
  1896   1896       char *p;
  1897   1897       WCHAR *native;
  1898   1898   
  1899   1899       if (GetCurrentDirectory(MAX_PATH, buffer) == 0) {
  1900   1900   	TclWinConvertError(GetLastError());
  1901   1901   	if (interp != NULL) {
  1902   1902   	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
................................................................................
  1911   1911        */
  1912   1912   
  1913   1913       native = (WCHAR *) buffer;
  1914   1914       if ((native[0] != '\0') && (native[1] == ':')
  1915   1915   	    && (native[2] == '\\') && (native[3] == '\\')) {
  1916   1916   	native += 2;
  1917   1917       }
  1918         -    Tcl_WinTCharToUtf((TCHAR *) native, -1, bufferPtr);
         1918  +    Tcl_WinTCharToUtf(native, -1, bufferPtr);
  1919   1919   
  1920   1920       /*
  1921   1921        * Convert to forward slashes for easier use in scripts.
  1922   1922        */
  1923   1923   
  1924   1924       for (p = Tcl_DStringValue(bufferPtr); *p != '\0'; p++) {
  1925   1925   	if (*p == '\\') {
................................................................................
  1966   1966    *	See stat documentation.
  1967   1967    *
  1968   1968    *----------------------------------------------------------------------
  1969   1969    */
  1970   1970   
  1971   1971   static int
  1972   1972   NativeStat(
  1973         -    const TCHAR *nativePath,	/* Path of file to stat */
         1973  +    const WCHAR *nativePath,	/* Path of file to stat */
  1974   1974       Tcl_StatBuf *statPtr,	/* Filled with results of stat call. */
  1975   1975       int checkLinks)		/* If non-zero, behave like 'lstat' */
  1976   1976   {
  1977   1977       DWORD attr;
  1978   1978       int dev, nlink = 1;
  1979   1979       unsigned short mode;
  1980   1980       unsigned int inode = 0;
................................................................................
  2107   2107    *	Calculate just the 'st_dev' field of a 'stat' structure.
  2108   2108    *
  2109   2109    *----------------------------------------------------------------------
  2110   2110    */
  2111   2111   
  2112   2112   static int
  2113   2113   NativeDev(
  2114         -    const TCHAR *nativePath)	/* Full path of file to stat */
         2114  +    const WCHAR *nativePath)	/* Full path of file to stat */
  2115   2115   {
  2116   2116       int dev;
  2117   2117       Tcl_DString ds;
  2118         -    TCHAR nativeFullPath[MAX_PATH];
  2119         -    TCHAR *nativePart;
         2118  +    WCHAR nativeFullPath[MAX_PATH];
         2119  +    WCHAR *nativePart;
  2120   2120       const char *fullPath;
  2121   2121   
  2122   2122       GetFullPathName(nativePath, MAX_PATH, nativeFullPath, &nativePart);
  2123   2123       fullPath = Tcl_WinTCharToUtf(nativeFullPath, -1, &ds);
  2124   2124   
  2125   2125       if ((fullPath[0] == '\\') && (fullPath[1] == '\\')) {
  2126   2126   	const char *p;
  2127   2127   	DWORD dw;
  2128         -	const TCHAR *nativeVol;
         2128  +	const WCHAR *nativeVol;
  2129   2129   	Tcl_DString volString;
  2130   2130   
  2131   2131   	p = strchr(fullPath + 2, '\\');
  2132   2132   	p = strchr(p + 1, '\\');
  2133   2133   	if (p == NULL) {
  2134   2134   	    /*
  2135   2135   	     * Add terminating backslash to fullpath or GetVolumeInformation()
................................................................................
  2283   2283    *----------------------------------------------------------------------
  2284   2284    */
  2285   2285   
  2286   2286   ClientData
  2287   2287   TclpGetNativeCwd(
  2288   2288       ClientData clientData)
  2289   2289   {
  2290         -    TCHAR buffer[MAX_PATH];
         2290  +    WCHAR buffer[MAX_PATH];
  2291   2291   
  2292   2292       if (GetCurrentDirectory(MAX_PATH, buffer) == 0) {
  2293   2293   	TclWinConvertError(GetLastError());
  2294   2294   	return NULL;
  2295   2295       }
  2296   2296   
  2297   2297       if (clientData != NULL) {
  2298         -	if (_tcscmp((const TCHAR*)clientData, buffer) == 0) {
         2298  +	if (wcscmp((const WCHAR*)clientData, buffer) == 0) {
  2299   2299   	    return clientData;
  2300   2300   	}
  2301   2301       }
  2302   2302   
  2303   2303       return TclNativeDupInternalRep(buffer);
  2304   2304   }
  2305   2305   
................................................................................
  2332   2332   TclpObjLink(
  2333   2333       Tcl_Obj *pathPtr,
  2334   2334       Tcl_Obj *toPtr,
  2335   2335       int linkAction)
  2336   2336   {
  2337   2337       if (toPtr != NULL) {
  2338   2338   	int res;
  2339         -	const TCHAR *LinkTarget;
  2340         -	const TCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
         2339  +	const WCHAR *LinkTarget;
         2340  +	const WCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
  2341   2341   	Tcl_Obj *normalizedToPtr = Tcl_FSGetNormalizedPath(NULL, toPtr);
  2342   2342   
  2343   2343   	if (normalizedToPtr == NULL) {
  2344   2344   	    return NULL;
  2345   2345   	}
  2346   2346   
  2347   2347   	LinkTarget = Tcl_FSGetNativePath(normalizedToPtr);
................................................................................
  2352   2352   	res = WinLink(LinkSource, LinkTarget, linkAction);
  2353   2353   	if (res == 0) {
  2354   2354   	    return toPtr;
  2355   2355   	} else {
  2356   2356   	    return NULL;
  2357   2357   	}
  2358   2358       } else {
  2359         -	const TCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
         2359  +	const WCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
  2360   2360   
  2361   2361   	if (LinkSource == NULL) {
  2362   2362   	    return NULL;
  2363   2363   	}
  2364   2364   	return WinReadLink(LinkSource);
  2365   2365       }
  2366   2366   }
................................................................................
  2386   2386   
  2387   2387   Tcl_Obj *
  2388   2388   TclpFilesystemPathType(
  2389   2389       Tcl_Obj *pathPtr)
  2390   2390   {
  2391   2391   #define VOL_BUF_SIZE 32
  2392   2392       int found;
  2393         -    TCHAR volType[VOL_BUF_SIZE];
         2393  +    WCHAR volType[VOL_BUF_SIZE];
  2394   2394       char *firstSeparator;
  2395   2395       const char *path;
  2396   2396       Tcl_Obj *normPath = Tcl_FSGetNormalizedPath(NULL, pathPtr);
  2397   2397   
  2398   2398       if (normPath == NULL) {
  2399   2399   	return NULL;
  2400   2400       }
................................................................................
  2487   2487   
  2488   2488   	if ((cur=='/' || cur==0) && (path != currentPathEndPosition)) {
  2489   2489   	    /*
  2490   2490   	     * Reached directory separator, or end of string.
  2491   2491   	     */
  2492   2492   
  2493   2493   	    WIN32_FILE_ATTRIBUTE_DATA data;
  2494         -	    const TCHAR *nativePath = Tcl_WinUtfToTChar(path,
         2494  +	    const WCHAR *nativePath = Tcl_WinUtfToTChar(path,
  2495   2495   		    currentPathEndPosition - path, &ds);
  2496   2496   
  2497   2497   	    if (GetFileAttributesEx(nativePath,
  2498   2498   		    GetFileExInfoStandard, &data) != TRUE) {
  2499   2499   		/*
  2500   2500   		 * File doesn't exist.
  2501   2501   		 */
................................................................................
  2630   2630   		     * path like that. However, to be nice we at least
  2631   2631   		     * don't mangle the path - we just add the dots as a
  2632   2632   		     * path segment and continue.
  2633   2633   		     */
  2634   2634   
  2635   2635   		    Tcl_DStringAppend(&dsNorm, ((const char *)nativePath)
  2636   2636   			    + Tcl_DStringLength(&ds)
  2637         -			    - (dotLen * sizeof(TCHAR)),
  2638         -			    (int)(dotLen * sizeof(TCHAR)));
         2637  +			    - (dotLen * sizeof(WCHAR)),
         2638  +			    dotLen * sizeof(WCHAR));
  2639   2639   		} else {
  2640   2640   		    /*
  2641   2641   		     * Normal path.
  2642   2642   		     */
  2643   2643   
  2644   2644   		    WIN32_FIND_DATAW fData;
  2645   2645   		    HANDLE handle;
................................................................................
  2689   2689   #ifdef TclNORM_LONG_PATH
  2690   2690   	/*
  2691   2691   	 * Convert the entire known path to long form.
  2692   2692   	 */
  2693   2693   
  2694   2694   	if (1) {
  2695   2695   	    WCHAR wpath[MAX_PATH];
  2696         -	    const TCHAR *nativePath =
         2696  +	    const WCHAR *nativePath =
  2697   2697   		    Tcl_WinUtfToTChar(path, lastValidPathEnd - path, &ds);
  2698   2698   	    DWORD wpathlen = GetLongPathNameProc(nativePath,
  2699         -		    (TCHAR *) wpath, MAX_PATH);
         2699  +		    (WCHAR *) wpath, MAX_PATH);
  2700   2700   
  2701   2701   	    /*
  2702   2702   	     * We have to make the drive letter uppercase.
  2703   2703   	     */
  2704   2704   
  2705   2705   	    if (wpath[0] >= L'a') {
  2706   2706   		wpath[0] -= (L'a' - L'A');
................................................................................
  2720   2720       if (lastValidPathEnd != NULL) {
  2721   2721   	/*
  2722   2722   	 * Concatenate the normalized string in dsNorm with the tail of the
  2723   2723   	 * path which we didn't recognise. The string in dsNorm is in the
  2724   2724   	 * native encoding, so we have to convert it to Utf.
  2725   2725   	 */
  2726   2726   
  2727         -	Tcl_WinTCharToUtf((const TCHAR *) Tcl_DStringValue(&dsNorm),
         2727  +	Tcl_WinTCharToUtf((const WCHAR *) Tcl_DStringValue(&dsNorm),
  2728   2728   		Tcl_DStringLength(&dsNorm), &ds);
  2729   2729   	nextCheckpoint = Tcl_DStringLength(&ds);
  2730   2730   	if (*lastValidPathEnd != 0) {
  2731   2731   	    /*
  2732   2732   	     * Not the end of the string.
  2733   2733   	     */
  2734   2734   
................................................................................
  2893   2893   
  2894   2894   Tcl_Obj *
  2895   2895   TclpNativeToNormalized(
  2896   2896       ClientData clientData)
  2897   2897   {
  2898   2898       Tcl_DString ds;
  2899   2899       Tcl_Obj *objPtr;
  2900         -    int len;
         2900  +    size_t len;
  2901   2901       char *copy, *p;
  2902   2902   
  2903         -    Tcl_WinTCharToUtf((const TCHAR *) clientData, -1, &ds);
         2903  +    Tcl_WinTCharToUtf((const WCHAR *) clientData, -1, &ds);
  2904   2904       copy = Tcl_DStringValue(&ds);
  2905   2905       len = Tcl_DStringLength(&ds);
  2906   2906   
  2907   2907       /*
  2908   2908        * Certain native path representations on Windows have this special prefix
  2909   2909        * to indicate that they are to be treated specially. For example
  2910   2910        * extremely long paths, or symlinks.
................................................................................
  3088   3088       char *copy;
  3089   3089       size_t len;
  3090   3090   
  3091   3091       if (clientData == NULL) {
  3092   3092   	return NULL;
  3093   3093       }
  3094   3094   
  3095         -    len = sizeof(TCHAR) * (_tcslen((const TCHAR *) clientData) + 1);
         3095  +    len = sizeof(WCHAR) * (wcslen((const WCHAR *) clientData) + 1);
  3096   3096   
  3097   3097       copy = Tcl_Alloc(len);
  3098   3098       memcpy(copy, clientData, len);
  3099   3099       return copy;
  3100   3100   }
  3101   3101   
  3102   3102   /*
................................................................................
  3119   3119   int
  3120   3120   TclpUtime(
  3121   3121       Tcl_Obj *pathPtr,		/* File to modify */
  3122   3122       struct utimbuf *tval)	/* New modification date structure */
  3123   3123   {
  3124   3124       int res = 0;
  3125   3125       HANDLE fileHandle;
  3126         -    const TCHAR *native;
         3126  +    const WCHAR *native;
  3127   3127       DWORD attr = 0;
  3128   3128       DWORD flags = FILE_ATTRIBUTE_NORMAL;
  3129   3129       FILETIME lastAccessTime, lastModTime;
  3130   3130   
  3131   3131       FromCTime(tval->actime, &lastAccessTime);
  3132   3132       FromCTime(tval->modtime, &lastModTime);
  3133   3133   
................................................................................
  3170   3170    *---------------------------------------------------------------------------
  3171   3171    */
  3172   3172   
  3173   3173   int
  3174   3174   TclWinFileOwned(
  3175   3175       Tcl_Obj *pathPtr)		/* File whose ownership is to be checked */
  3176   3176   {
  3177         -    const TCHAR *native;
         3177  +    const WCHAR *native;
  3178   3178       PSID ownerSid = NULL;
  3179   3179       PSECURITY_DESCRIPTOR secd = NULL;
  3180   3180       HANDLE token;
  3181   3181       LPBYTE buf = NULL;
  3182   3182       DWORD bufsz;
  3183   3183       int owned = 0;
  3184   3184   

Changes to win/tclWinInit.c.

   151    151   
   152    152       TclWinInit(GetModuleHandle(NULL));
   153    153   #endif
   154    154   
   155    155       /*
   156    156        * Fill available functions depending on windows version
   157    157        */
   158         -    handle = GetModuleHandle(TEXT("KERNEL32"));
          158  +    handle = GetModuleHandle(L"KERNEL32");
   159    159       tclWinProcs.cancelSynchronousIo =
   160    160   	    (BOOL (WINAPI *)(HANDLE)) GetProcAddress(handle,
   161    161   	    "CancelSynchronousIo");
   162    162   }
   163    163   
   164    164   /*
   165    165    *-------------------------------------------------------------------------
................................................................................
   184    184       size_t *lengthPtr,
   185    185       Tcl_Encoding *encodingPtr)
   186    186   {
   187    187   #define LIBRARY_SIZE	    64
   188    188       Tcl_Obj *pathPtr;
   189    189       char installLib[LIBRARY_SIZE];
   190    190       const char *bytes;
          191  +    size_t length;
   191    192   
   192    193       pathPtr = Tcl_NewObj();
   193    194   
   194    195       /*
   195    196        * Initialize the substring used when locating the script library. The
   196    197        * installLib variable computes the script library path relative to the
   197    198        * installed DLL.
................................................................................
   219    220        * Look for the library in its source checkout location.
   220    221        */
   221    222   
   222    223       Tcl_ListObjAppendElement(NULL, pathPtr,
   223    224   	    TclGetProcessGlobalValue(&sourceLibraryDir));
   224    225   
   225    226       *encodingPtr = NULL;
   226         -    bytes = TclGetStringFromObj(pathPtr, lengthPtr);
   227         -    *valuePtr = Tcl_Alloc(*lengthPtr + 1);
   228         -    memcpy(*valuePtr, bytes, *lengthPtr + 1);
          227  +    bytes = TclGetStringFromObj(pathPtr, &length);
          228  +    *lengthPtr = length++;
          229  +    *valuePtr = Tcl_Alloc(length);
          230  +    memcpy(*valuePtr, bytes, length);
   229    231       Tcl_DecrRefCount(pathPtr);
   230    232   }
   231    233   
   232    234   /*
   233    235    *---------------------------------------------------------------------------
   234    236    *
   235    237    * AppendEnvironment --
................................................................................
   311    313   	    Tcl_DStringInit(&ds);
   312    314   	    (void) Tcl_JoinPath(pathc, pathv, &ds);
   313    315   	    objPtr = TclDStringToObj(&ds);
   314    316   	} else {
   315    317   	    objPtr = Tcl_NewStringObj(buf, -1);
   316    318   	}
   317    319   	Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
   318         -	Tcl_Free(pathv);
          320  +	Tcl_Free((void *)pathv);
   319    321       }
   320    322   }
   321    323   
   322    324   /*
   323    325    *---------------------------------------------------------------------------
   324    326    *
   325    327    * InitializeDefaultLibraryDir --
................................................................................
   463    465   TclpGetUserName(
   464    466       Tcl_DString *bufferPtr)	/* Uninitialized or free DString filled with
   465    467   				 * the name of user. */
   466    468   {
   467    469       Tcl_DStringInit(bufferPtr);
   468    470   
   469    471       if (TclGetEnv("USERNAME", bufferPtr) == NULL) {
   470         -	TCHAR szUserName[UNLEN+1];
          472  +	WCHAR szUserName[UNLEN+1];
   471    473   	DWORD cchUserNameLen = UNLEN;
   472    474   
   473    475   	if (!GetUserName(szUserName, &cchUserNameLen)) {
   474    476   	    return NULL;
   475    477   	}
   476    478   	cchUserNameLen--;
   477         -	cchUserNameLen *= sizeof(TCHAR);
          479  +	cchUserNameLen *= sizeof(WCHAR);
   478    480   	Tcl_WinTCharToUtf(szUserName, cchUserNameLen, bufferPtr);
   479    481       }
   480    482       return Tcl_DStringValue(bufferPtr);
   481    483   }
   482    484   
   483    485   /*
   484    486    *---------------------------------------------------------------------------
................................................................................
   511    513       static int osInfoInitialized = 0;
   512    514       Tcl_DString ds;
   513    515   
   514    516       Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL,
   515    517   	    TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY);
   516    518   
   517    519       if (!osInfoInitialized) {
   518         -	HMODULE handle = GetModuleHandle(TEXT("NTDLL"));
          520  +	HMODULE handle = GetModuleHandle(L"NTDLL");
   519    521   	int(__stdcall *getversion)(void *) =
   520    522   		(int(__stdcall *)(void *)) GetProcAddress(handle, "RtlGetVersion");
   521    523   	osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
   522    524   	if (!getversion || getversion(&osInfo)) {
   523    525   	    GetVersionExW(&osInfo);
   524    526   	}
   525    527   	osInfoInitialized = 1;

Changes to win/tclWinInt.h.

    42     42   
    43     43   /*
    44     44    * Declarations of functions that are not accessible by way of the
    45     45    * stubs table.
    46     46    */
    47     47   
    48     48   MODULE_SCOPE char	TclWinDriveLetterForVolMountPoint(
    49         -			    const TCHAR *mountPoint);
           49  +			    const WCHAR *mountPoint);
    50     50   MODULE_SCOPE void	TclWinEncodingsCleanup();
    51     51   MODULE_SCOPE void	TclWinInit(HINSTANCE hInst);
    52     52   MODULE_SCOPE TclFile	TclWinMakeFile(HANDLE handle);
    53     53   MODULE_SCOPE Tcl_Channel TclWinOpenConsoleChannel(HANDLE handle,
    54     54   			    char *channelName, int permissions);
    55     55   MODULE_SCOPE Tcl_Channel TclWinOpenFileChannel(HANDLE handle, char *channelName,
    56     56   			    int permissions, int appendMode);
    57     57   MODULE_SCOPE Tcl_Channel TclWinOpenSerialChannel(HANDLE handle,
    58     58   			    char *channelName, int permissions);
    59         -MODULE_SCOPE HANDLE	TclWinSerialOpen(HANDLE handle, const TCHAR *name,
           59  +MODULE_SCOPE HANDLE	TclWinSerialOpen(HANDLE handle, const WCHAR *name,
    60     60   			    DWORD access);
    61     61   MODULE_SCOPE int	TclWinSymLinkCopyDirectory(const TCHAR *LinkOriginal,
    62     62   			    const TCHAR *LinkCopy);
    63     63   MODULE_SCOPE int	TclWinSymLinkDelete(const TCHAR *LinkOriginal,
    64     64   			    int linkOnly);
    65     65   MODULE_SCOPE int        TclWinFileOwned(Tcl_Obj *);
    66     66   

Changes to win/tclWinPipe.c.

   187    187   			    int toRead, int *errorCode);
   188    188   static int		PipeOutputProc(ClientData instanceData,
   189    189   			    const char *buf, int toWrite, int *errorCode);
   190    190   static DWORD WINAPI	PipeReaderThread(LPVOID arg);
   191    191   static void		PipeSetupProc(ClientData clientData, int flags);
   192    192   static void		PipeWatchProc(ClientData instanceData, int mask);
   193    193   static DWORD WINAPI	PipeWriterThread(LPVOID arg);
   194         -static int		TempFileName(TCHAR name[MAX_PATH]);
          194  +static int		TempFileName(WCHAR name[MAX_PATH]);
   195    195   static int		WaitForRead(PipeInfo *infoPtr, int blocking);
   196    196   static void		PipeThreadActionProc(ClientData instanceData,
   197    197   			    int action);
   198    198   
   199    199   /*
   200    200    * This structure describes the channel type structure for command pipe based
   201    201    * I/O.
................................................................................
   459    459    *	None.
   460    460    *
   461    461    *----------------------------------------------------------------------
   462    462    */
   463    463   
   464    464   static int
   465    465   TempFileName(
   466         -    TCHAR name[MAX_PATH])	/* Buffer in which name for temporary file
          466  +    WCHAR name[MAX_PATH])	/* Buffer in which name for temporary file
   467    467   				 * gets stored. */
   468    468   {
   469         -    const TCHAR *prefix = TEXT("TCL");
          469  +    const WCHAR *prefix = L"TCL";
   470    470       if (GetTempPath(MAX_PATH, name) != 0) {
   471    471   	if (GetTempFileName(name, prefix, 0, name) != 0) {
   472    472   	    return 1;
   473    473   	}
   474    474       }
   475    475       name[0] = '.';
   476    476       name[1] = '\0';
................................................................................
   529    529   TclpOpenFile(
   530    530       const char *path,		/* The name of the file to open. */
   531    531       int mode)			/* In what mode to open the file? */
   532    532   {
   533    533       HANDLE handle;
   534    534       DWORD accessMode, createMode, shareMode, flags;
   535    535       Tcl_DString ds;
   536         -    const TCHAR *nativePath;
          536  +    const WCHAR *nativePath;
   537    537   
   538    538       /*
   539    539        * Map the access bits to the NT access mode.
   540    540        */
   541    541   
   542    542       switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) {
   543    543       case O_RDONLY:
................................................................................
   646    646    *----------------------------------------------------------------------
   647    647    */
   648    648   
   649    649   TclFile
   650    650   TclpCreateTempFile(
   651    651       const char *contents)	/* String to write into temp file, or NULL. */
   652    652   {
   653         -    TCHAR name[MAX_PATH];
          653  +    WCHAR name[MAX_PATH];
   654    654       const char *native;
   655    655       Tcl_DString dstring;
   656    656       HANDLE handle;
   657    657   
   658    658       if (TempFileName(name) == 0) {
   659    659   	return NULL;
   660    660       }
................................................................................
   740    740    *
   741    741    *----------------------------------------------------------------------
   742    742    */
   743    743   
   744    744   Tcl_Obj *
   745    745   TclpTempFileName(void)
   746    746   {
   747         -    TCHAR fileName[MAX_PATH];
          747  +    WCHAR fileName[MAX_PATH];
   748    748   
   749    749       if (TempFileName(fileName) == 0) {
   750    750   	return NULL;
   751    751       }
   752    752   
   753    753       return TclpNativeToNormalized(fileName);
   754    754   }
................................................................................
   932    932   				 * from the child will be discarded. errorFile
   933    933   				 * may be the same as outputFile. */
   934    934       Tcl_Pid *pidPtr)		/* If this function is successful, pidPtr is
   935    935   				 * filled with the process id of the child
   936    936   				 * process. */
   937    937   {
   938    938       int result, applType, createFlags;
   939         -    Tcl_DString cmdLine;	/* Complete command line (TCHAR). */
          939  +    Tcl_DString cmdLine;	/* Complete command line (WCHAR). */
   940    940       STARTUPINFO startInfo;
   941    941       PROCESS_INFORMATION procInfo;
   942    942       SECURITY_ATTRIBUTES secAtts;
   943    943       HANDLE hProcess, h, inputHandle, outputHandle, errorHandle;
   944    944       char execPath[MAX_PATH * 3];
   945    945       WinFile *filePtr;
   946    946   
................................................................................
  1044   1044   	 * the child process would hang forever waiting for input from the
  1045   1045   	 * unmapped console window used by the helper application.
  1046   1046   	 *
  1047   1047   	 * Fortunately, the helper application will detect a closed pipe as a
  1048   1048   	 * sink.
  1049   1049   	 */
  1050   1050   
  1051         -	startInfo.hStdOutput = CreateFile(TEXT("NUL:"), GENERIC_WRITE, 0,
         1051  +	startInfo.hStdOutput = CreateFile(L"NUL:", GENERIC_WRITE, 0,
  1052   1052   		&secAtts, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  1053   1053       } else {
  1054   1054   	DuplicateHandle(hProcess, outputHandle, hProcess,
  1055   1055   		&startInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
  1056   1056       }
  1057   1057       if (startInfo.hStdOutput == INVALID_HANDLE_VALUE) {
  1058   1058   	TclWinConvertError(GetLastError());
................................................................................
  1064   1064   
  1065   1065       if (errorHandle == INVALID_HANDLE_VALUE) {
  1066   1066   	/*
  1067   1067   	 * If handle was not set, errors should be sent to an infinitely deep
  1068   1068   	 * sink.
  1069   1069   	 */
  1070   1070   
  1071         -	startInfo.hStdError = CreateFile(TEXT("NUL:"), GENERIC_WRITE, 0,
         1071  +	startInfo.hStdError = CreateFile(L"NUL:", GENERIC_WRITE, 0,
  1072   1072   		&secAtts, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  1073   1073       } else {
  1074   1074   	DuplicateHandle(hProcess, errorHandle, hProcess, &startInfo.hStdError,
  1075   1075   		0, TRUE, DUPLICATE_SAME_ACCESS);
  1076   1076       }
  1077   1077       if (startInfo.hStdError == INVALID_HANDLE_VALUE) {
  1078   1078   	TclWinConvertError(GetLastError());
................................................................................
  1130   1130        * Additionally, when calling a 16-bit dos or windows application, all
  1131   1131        * path names must use the short, cryptic, path format (e.g., using
  1132   1132        * ab~1.def instead of "a b.default").
  1133   1133        */
  1134   1134   
  1135   1135       BuildCommandLine(execPath, argc, argv, &cmdLine);
  1136   1136   
  1137         -    if (CreateProcess(NULL, (TCHAR *) Tcl_DStringValue(&cmdLine),
         1137  +    if (CreateProcess(NULL, (WCHAR *) Tcl_DStringValue(&cmdLine),
  1138   1138   	    NULL, NULL, TRUE, (DWORD) createFlags, NULL, NULL, &startInfo,
  1139   1139   	    &procInfo) == 0) {
  1140   1140   	TclWinConvertError(GetLastError());
  1141   1141   	Tcl_SetObjResult(interp, Tcl_ObjPrintf("couldn't execute \"%s\": %s",
  1142   1142   		argv[0], Tcl_PosixError(interp)));
  1143   1143   	goto end;
  1144   1144       }
................................................................................
  1256   1256       Tcl_Interp *interp,		/* Interp, for error message. */
  1257   1257       const char *originalName,	/* Name of the application to find. */
  1258   1258       char fullName[])		/* Filled with complete path to
  1259   1259   				 * application. */
  1260   1260   {
  1261   1261       int applType, i, nameLen, found;
  1262   1262       HANDLE hFile;
  1263         -    TCHAR *rest;
         1263  +    WCHAR *rest;
  1264   1264       char *ext;
  1265   1265       char buf[2];
  1266   1266       DWORD attr, read;
  1267   1267       IMAGE_DOS_HEADER header;
  1268   1268       Tcl_DString nameBuf, ds;
  1269         -    const TCHAR *nativeName;
  1270         -    TCHAR nativeFullPath[MAX_PATH];
         1269  +    const WCHAR *nativeName;
         1270  +    WCHAR nativeFullPath[MAX_PATH];
  1271   1271       static const char extensions[][5] = {"", ".com", ".exe", ".bat", ".cmd"};
  1272   1272   
  1273   1273       /*
  1274   1274        * Look for the program as an external program. First try the name as it
  1275   1275        * is, then try adding .com, .exe, .bat and .cmd, in that order, to the name,
  1276   1276        * looking for an executable.
  1277   1277        *
................................................................................
  1508   1508   static void
  1509   1509   BuildCommandLine(
  1510   1510       const char *executable,	/* Full path of executable (including
  1511   1511   				 * extension). Replacement for argv[0]. */
  1512   1512       int argc,			/* Number of arguments. */
  1513   1513       const char **argv,		/* Argument strings in UTF. */
  1514   1514       Tcl_DString *linePtr)	/* Initialized Tcl_DString that receives the
  1515         -				 * command line (TCHAR). */
         1515  +				 * command line (WCHAR). */
  1516   1516   {
  1517   1517       const char *arg, *start, *special, *bspos;
  1518   1518       int quote = 0, i;
  1519   1519       Tcl_DString ds;
  1520   1520   
  1521   1521       /* characters to enclose in quotes if unpaired quote flag set */
  1522   1522       static const char specMetaChars[] = "&|^<>!()%";
................................................................................
  3097   3097   Tcl_Channel
  3098   3098   TclpOpenTemporaryFile(
  3099   3099       Tcl_Obj *dirObj,
  3100   3100       Tcl_Obj *basenameObj,
  3101   3101       Tcl_Obj *extensionObj,
  3102   3102       Tcl_Obj *resultingNameObj)
  3103   3103   {
  3104         -    TCHAR name[MAX_PATH];
         3104  +    WCHAR name[MAX_PATH];
  3105   3105       char *namePtr;
  3106   3106       HANDLE handle;
  3107   3107       DWORD flags = FILE_ATTRIBUTE_TEMPORARY;
  3108   3108       size_t length;
  3109   3109       int counter, counter2;
  3110   3110       Tcl_DString buf;
  3111   3111   
................................................................................
  3114   3114       }
  3115   3115   
  3116   3116       namePtr = (char *) name;
  3117   3117       length = GetTempPath(MAX_PATH, name);
  3118   3118       if (length == 0) {
  3119   3119   	goto gotError;
  3120   3120       }
  3121         -    namePtr += length * sizeof(TCHAR);
         3121  +    namePtr += length * sizeof(WCHAR);
  3122   3122       if (basenameObj) {
  3123         -	size_t length;
  3124   3123   	const char *string = TclGetStringFromObj(basenameObj, &length);
  3125   3124   
  3126   3125   	Tcl_WinUtfToTChar(string, length, &buf);
  3127   3126   	memcpy(namePtr, Tcl_DStringValue(&buf), Tcl_DStringLength(&buf));
  3128   3127   	namePtr += Tcl_DStringLength(&buf);
  3129   3128   	Tcl_DStringFree(&buf);
  3130   3129       } else {
  3131         -	const TCHAR *baseStr = TEXT("TCL");
  3132         -	length = 3 * sizeof(TCHAR);
         3130  +	const WCHAR *baseStr = L"TCL";
         3131  +	length = 3 * sizeof(WCHAR);
  3133   3132   
  3134   3133   	memcpy(namePtr, baseStr, length);
  3135   3134   	namePtr += length;
  3136   3135       }
  3137   3136       counter = TclpGetClicks() % 65533;
  3138   3137       counter2 = 1024;			/* Only try this many times! Prevents
  3139   3138   					 * an infinite loop. */

Changes to win/tclWinPort.h.

    48     48   #define INCL_WINSOCK_API_TYPEDEFS   1
    49     49   #include <winsock2.h>
    50     50   #include <ws2tcpip.h>
    51     51   #ifdef HAVE_WSPIAPI_H
    52     52   #   include <wspiapi.h>
    53     53   #endif
    54     54   
    55         -#ifdef CHECK_UNICODE_CALLS
    56         -#   define _UNICODE
    57         -#   define UNICODE
    58         -#   define __TCHAR_DEFINED
    59         -    typedef float *_TCHAR;
    60         -#   define _TCHAR_DEFINED
    61         -    typedef float *TCHAR;
    62         -#endif /* CHECK_UNICODE_CALLS */
    63         -
    64     55   /*
    65     56    *  Pull in the typedef of TCHAR for windows.
    66     57    */
    67     58   #include <tchar.h>
    68     59   #ifndef _TCHAR_DEFINED
    69     60       /* Borland seems to forget to set this. */
    70     61       typedef _TCHAR TCHAR;

Changes to win/tclWinSerial.c.

  1364   1364    *
  1365   1365    *----------------------------------------------------------------------
  1366   1366    */
  1367   1367   
  1368   1368   HANDLE
  1369   1369   TclWinSerialOpen(
  1370   1370       HANDLE handle,
  1371         -    const TCHAR *name,
         1371  +    const WCHAR *name,
  1372   1372       DWORD access)
  1373   1373   {
  1374   1374       SerialInit();
  1375   1375   
  1376   1376       /*
  1377   1377        * If an open channel is specified, close it
  1378   1378        */
................................................................................
  1591   1591       const char *value)		/* New value for option. */
  1592   1592   {
  1593   1593       SerialInfo *infoPtr;
  1594   1594       DCB dcb;
  1595   1595       BOOL result, flag;
  1596   1596       size_t len, vlen;
  1597   1597       Tcl_DString ds;
  1598         -    const TCHAR *native;
         1598  +    const WCHAR *native;
  1599   1599       int argc;
  1600   1600       const char **argv;
  1601   1601   
  1602   1602       infoPtr = (SerialInfo *) instanceData;
  1603   1603   
  1604   1604       /*
  1605   1605        * Parse options. This would be far easier if we had Tcl_Objs to work with
................................................................................
  1714   1714   	    return TCL_ERROR;
  1715   1715   	}
  1716   1716   	if (argc != 2) {
  1717   1717   	badXchar:
  1718   1718   	    if (interp != NULL) {
  1719   1719   		Tcl_SetObjResult(interp, Tcl_NewStringObj(
  1720   1720   			"bad value for -xchar: should be a list of"
  1721         -			" two elements with each a single character", -1));
         1721  +			" two elements with each a single 8-bit character", -1));
  1722   1722   		Tcl_SetErrorCode(interp, "TCL", "VALUE", "XCHAR", NULL);
  1723   1723   	    }
  1724         -	    Tcl_Free(argv);
         1724  +	    Tcl_Free((void *)argv);
  1725   1725   	    return TCL_ERROR;
  1726   1726   	}
  1727   1727   
  1728   1728   	/*
  1729   1729   	 * These dereferences are safe, even in the zero-length string cases,
  1730   1730   	 * because that just makes the xon/xoff character into NUL. When the
  1731   1731   	 * character looks like it is UTF-8 encoded, decode it before casting
................................................................................
  1738   1738   	dcb.XonChar = argv[0][0];
  1739   1739   	dcb.XoffChar = argv[1][0];
  1740   1740   	if (argv[0][0] & 0x80 || argv[1][0] & 0x80) {
  1741   1741   	    Tcl_UniChar character = 0;
  1742   1742   	    int charLen;
  1743   1743   
  1744   1744   	    charLen = Tcl_UtfToUniChar(argv[0], &character);
  1745         -	    if (argv[0][charLen]) {
         1745  +	    if ((character > 0xFF) || argv[0][charLen]) {
  1746   1746   		goto badXchar;
  1747   1747   	    }
  1748   1748   	    dcb.XonChar = (char) character;
  1749   1749   	    charLen = Tcl_UtfToUniChar(argv[1], &character);
  1750         -	    if (argv[1][charLen]) {
         1750  +	    if ((character > 0xFF) || argv[1][charLen]) {
  1751   1751   		goto badXchar;
  1752   1752   	    }
  1753   1753   	    dcb.XoffChar = (char) character;
  1754   1754   	}
  1755         -	Tcl_Free(argv);
         1755  +	Tcl_Free((void *)argv);
  1756   1756   
  1757   1757   	if (!SetCommState(infoPtr->handle, &dcb)) {
  1758   1758   	    goto setStateFailed;
  1759   1759   	}
  1760   1760   	return TCL_OK;
  1761   1761       }
  1762   1762   
................................................................................
  1773   1773   	if ((argc % 2) == 1) {
  1774   1774   	    if (interp != NULL) {
  1775   1775   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1776   1776   			"bad value \"%s\" for -ttycontrol: should be "
  1777   1777   			"a list of signal,value pairs", value));
  1778   1778   		Tcl_SetErrorCode(interp, "TCL", "VALUE", "TTYCONTROL", NULL);
  1779   1779   	    }
  1780         -	    Tcl_Free(argv);
         1780  +	    Tcl_Free((void *)argv);
  1781   1781   	    return TCL_ERROR;
  1782   1782   	}
  1783   1783   
  1784   1784   	for (i = 0; i < argc - 1; i += 2) {
  1785   1785   	    if (Tcl_GetBoolean(interp, argv[i+1], &flag) == TCL_ERROR) {
  1786   1786   		result = TCL_ERROR;
  1787   1787   		break;
................................................................................
  1831   1831   			    NULL);
  1832   1832   		}
  1833   1833   		result = TCL_ERROR;
  1834   1834   		break;
  1835   1835   	    }
  1836   1836   	}
  1837   1837   
  1838         -	Tcl_Free(argv);
         1838  +	Tcl_Free((void *)argv);
  1839   1839   	return result;
  1840   1840       }
  1841   1841   
  1842   1842       /*
  1843   1843        * Option -sysbuffer {read_size write_size}
  1844   1844        * Option -sysbuffer read_size
  1845   1845        */
................................................................................
  1857   1857   	if (argc == 1) {
  1858   1858   	    inSize = atoi(argv[0]);
  1859   1859   	    outSize = infoPtr->sysBufWrite;
  1860   1860   	} else if (argc == 2) {
  1861   1861   	    inSize  = atoi(argv[0]);
  1862   1862   	    outSize = atoi(argv[1]);
  1863   1863   	}
  1864         -	Tcl_Free(argv);
         1864  +	Tcl_Free((void *)argv);
  1865   1865   
  1866   1866   	if ((argc < 1) || (argc > 2) || (inSize <= 0) || (outSize <= 0)) {
  1867   1867   	    if (interp != NULL) {
  1868   1868   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  1869   1869   			"bad value \"%s\" for -sysbuffer: should be "
  1870   1870   			"a list of one or two integers > 0", value));
  1871   1871   		Tcl_SetErrorCode(interp, "TCL", "VALUE", "SYS_BUFFER", NULL);
................................................................................
  2073   2073        */
  2074   2074   
  2075   2075       if (len == 0) {
  2076   2076   	Tcl_DStringAppendElement(dsPtr, "-xchar");
  2077   2077   	Tcl_DStringStartSublist(dsPtr);
  2078   2078       }
  2079   2079       if (len==0 || (len>1 && strncmp(optionName, "-xchar", len) == 0)) {
  2080         -	char buf[4];
         2080  +	char buf[TCL_UTF_MAX];
  2081   2081   	valid = 1;
  2082   2082   
  2083   2083   	if (!GetCommState(infoPtr->handle, &dcb)) {
  2084   2084   	    if (interp != NULL) {
  2085   2085   		TclWinConvertError(GetLastError());
  2086   2086   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  2087   2087   			"can't get comm state: %s", Tcl_PosixError(interp)));
  2088   2088   	    }
  2089   2089   	    return TCL_ERROR;
  2090   2090   	}
  2091         -	sprintf(buf, "%c", dcb.XonChar);
         2091  +	buf[Tcl_UniCharToUtf(UCHAR(dcb.XonChar), buf)] = '\0';
  2092   2092   	Tcl_DStringAppendElement(dsPtr, buf);
  2093         -	sprintf(buf, "%c", dcb.XoffChar);
         2093  +	buf[Tcl_UniCharToUtf(UCHAR(dcb.XoffChar), buf)] = '\0';
  2094   2094   	Tcl_DStringAppendElement(dsPtr, buf);
  2095   2095       }
  2096   2096       if (len == 0) {
  2097   2097   	Tcl_DStringEndSublist(dsPtr);
  2098   2098       }
  2099   2099   
  2100   2100       /*

Changes to win/tclWinSock.c.

    78     78   /*
    79     79    * The following variable is used to tell whether this module has been
    80     80    * initialized.  If 1, initialization of sockets was successful, if -1 then
    81     81    * socket initialization failed (WSAStartup failed).
    82     82    */
    83     83   
    84     84   static int initialized = 0;
    85         -static const TCHAR className[] = TEXT("TclSocket");
           85  +static const WCHAR className[] = L"TclSocket";
    86     86   TCL_DECLARE_MUTEX(socketMutex)
    87     87   
    88     88   /*
    89     89    * The following defines declare the messages used on socket windows.
    90     90    */
    91     91   
    92     92   #define SOCKET_MESSAGE		WM_USER+1
................................................................................
   359    359   
   360    360   void
   361    361   InitializeHostName(
   362    362       char **valuePtr,
   363    363       size_t *lengthPtr,
   364    364       Tcl_Encoding *encodingPtr)
   365    365   {
   366         -    TCHAR tbuf[MAX_COMPUTERNAME_LENGTH + 1];
          366  +    WCHAR tbuf[MAX_COMPUTERNAME_LENGTH + 1];
   367    367       DWORD length = MAX_COMPUTERNAME_LENGTH + 1;
   368    368       Tcl_DString ds;
   369    369   
   370    370       if (GetComputerName(tbuf, &length) != 0) {
   371    371   	/*
   372    372   	 * Convert string from native to UTF then change to lowercase.
   373    373   	 */