Tcl Source Code

Check-in [65a911f5d4]
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 8.7
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-445-api-fix
Files: files | file ages | folders
SHA3-256: 65a911f5d459284f2368a47d5702a52a4d0ecb5114cffe50979bd0177f6afc6f
User & Date: dgp 2019-03-15 15:47:34
Context
2019-03-18
15:25
merge 8.7 check-in: 9c1a58d079 user: dgp tags: tip-445-api-fix
2019-03-15
15:47
merge 8.7 check-in: 65a911f5d4 user: dgp tags: tip-445-api-fix
2019-03-14
19:52
Make internal libtommath stub entries deprecated: Those are not supposed to be called in extensions check-in: 99c1ed4d8a user: jan.nijtmans tags: core-8-branch
2019-03-08
14:56
merge 8.7 check-in: 1dd923d0cf user: dgp tags: tip-445-api-fix
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       int wanted)			/* want enough room for this one */
   478    477   {
   479    478       struct subre **p;
   480         -    size_t n;
          479  +    int n;
   481    480   
   482         -    assert(wanted > 0 && (size_t)wanted >= v->nsubs);
   483         -    n = (size_t)wanted * 3 / 2 + 1;
          481  +    assert(wanted > 0 && wanted >= v->nsubs);
          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 *));
   488    487   	}
   489    488       } else {
   490    489   	p = (struct subre **) REALLOC(v->subs, n*sizeof(struct subre *));
................................................................................
   495    494       }
   496    495   
   497    496       v->subs = p;
   498    497       for (p = &v->subs[v->nsubs]; v->nsubs < n; p++, v->nsubs++) {
   499    498   	*p = NULL;
   500    499       }
   501    500       assert(v->nsubs == n);
   502         -    assert((size_t)wanted < v->nsubs);
          501  +    assert(wanted < v->nsubs);
   503    502   }
   504    503   
   505    504   /*
   506    505    - freev - free vars struct's substructures where necessary
   507    506    * Optionally does error-number setting, and always returns error code (if
   508    507    * any), to make error-handling code terser.
   509    508    ^ static int freev(struct vars *, int);
................................................................................
   950    949   	 */
   951    950   
   952    951       case '(':			/* value flags as capturing or non */
   953    952   	cap = (type == LACON) ? 0 : v->nextvalue;
   954    953   	if (cap) {
   955    954   	    v->nsubexp++;
   956    955   	    subno = v->nsubexp;
   957         -	    if ((size_t)subno >= v->nsubs) {
          956  +	    if (subno >= v->nsubs) {
   958    957   		moresubs(v, subno);
   959    958   	    }
   960         -	    assert((size_t)subno < v->nsubs);
          959  +	    assert(subno < v->nsubs);
   961    960   	} else {
   962    961   	    atomtype = PLAIN;	/* something that's not '(' */
   963    962   	}
   964    963   	NEXT();
   965    964   
   966    965   	/*
   967    966   	 * Need new endpoints because tree will contain pointers.

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);

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
................................................................................
  2397   2397       *dstCharsPtr = numChars;
  2398   2398       return result;
  2399   2399   }
  2400   2400   
  2401   2401   /*
  2402   2402    *-------------------------------------------------------------------------
  2403   2403    *
  2404         - * UnicodeToUtfProc --
         2404  + * UniCharToUtfProc --
  2405   2405    *
  2406   2406    *	Convert from Unicode to UTF-8.
  2407   2407    *
  2408   2408    * Results:
  2409   2409    *	Returns TCL_OK if conversion was successful.
  2410   2410    *
  2411   2411    * Side effects:
  2412   2412    *	None.
  2413   2413    *
  2414   2414    *-------------------------------------------------------------------------
  2415   2415    */
  2416   2416   
  2417   2417   static int
  2418         -UnicodeToUtfProc(
         2418  +UniCharToUtfProc(
  2419   2419       ClientData clientData,	/* Not used. */
  2420   2420       const char *src,		/* Source string in Unicode. */
  2421   2421       int srcLen,			/* Source string length in bytes. */
  2422   2422       int flags,			/* Conversion control flags. */
  2423   2423       Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
  2424   2424   				 * information used during a piecewise
  2425   2425   				 * conversion. Contents of statePtr are
................................................................................
  2440   2440       int *dstCharsPtr)		/* Filled with the number of characters that
  2441   2441   				 * correspond to the bytes stored in the
  2442   2442   				 * output buffer. */
  2443   2443   {
  2444   2444       const char *srcStart, *srcEnd;
  2445   2445       const char *dstEnd, *dstStart;
  2446   2446       int result, numChars, charLimit = INT_MAX;
  2447         -    Tcl_UniChar *chPtr = (Tcl_UniChar *) statePtr;
         2447  +    unsigned short ch;
  2448   2448   
  2449         -    if (flags & TCL_ENCODING_START) {
  2450         -    	*statePtr = 0;
  2451         -    }
  2452   2449       if (flags & TCL_ENCODING_CHAR_LIMIT) {
  2453   2450   	charLimit = *dstCharsPtr;
  2454   2451       }
  2455   2452       result = TCL_OK;
  2456         -    if ((srcLen % sizeof(Tcl_UniChar)) != 0) {
         2453  +    if ((srcLen % sizeof(unsigned short)) != 0) {
  2457   2454   	result = TCL_CONVERT_MULTIBYTE;
  2458         -	srcLen /= sizeof(Tcl_UniChar);
  2459         -	srcLen *= sizeof(Tcl_UniChar);
         2455  +	srcLen /= sizeof(unsigned short);
         2456  +	srcLen *= sizeof(unsigned short);
  2460   2457       }
  2461   2458   
  2462   2459       srcStart = src;
  2463   2460       srcEnd = src + srcLen;
  2464   2461   
  2465   2462       dstStart = dst;
  2466   2463       dstEnd = dst + dstLen - TCL_UTF_MAX;
................................................................................
  2469   2466   	if (dst > dstEnd) {
  2470   2467   	    result = TCL_CONVERT_NOSPACE;
  2471   2468   	    break;
  2472   2469   	}
  2473   2470   
  2474   2471   	/*
  2475   2472   	 * Special case for 1-byte utf chars for speed. Make sure we work with
  2476         -	 * Tcl_UniChar-size data.
         2473  +	 * unsigned short-size data.
  2477   2474   	 */
  2478   2475   
  2479         -	*chPtr = *(Tcl_UniChar *)src;
  2480         -	if (*chPtr && *chPtr < 0x80) {
  2481         -	    *dst++ = (*chPtr & 0xFF);
         2476  +	ch = *(unsigned short *)src;
         2477  +	if (ch && ch < 0x80) {
         2478  +	    *dst++ = (ch & 0xFF);
  2482   2479   	} else {
  2483         -	    dst += Tcl_UniCharToUtf(*chPtr, dst);
         2480  +	    dst += Tcl_UniCharToUtf(ch, dst);
  2484   2481   	}
  2485         -	src += sizeof(Tcl_UniChar);
         2482  +	src += sizeof(unsigned short);
  2486   2483       }
  2487   2484   
  2488   2485       *srcReadPtr = src - srcStart;
  2489   2486       *dstWrotePtr = dst - dstStart;
  2490   2487       *dstCharsPtr = numChars;
  2491   2488       return result;
  2492   2489   }
  2493   2490   
  2494   2491   /*
  2495   2492    *-------------------------------------------------------------------------
  2496   2493    *
  2497         - * UtfToUnicodeProc --
         2494  + * UtfToUniCharProc --
  2498   2495    *
  2499   2496    *	Convert from UTF-8 to Unicode.
  2500   2497    *
  2501   2498    * Results:
  2502   2499    *	Returns TCL_OK if conversion was successful.
  2503   2500    *
  2504   2501    * Side effects:
  2505   2502    *	None.
  2506   2503    *
  2507   2504    *-------------------------------------------------------------------------
  2508   2505    */
  2509   2506   
  2510   2507   static int
  2511         -UtfToUnicodeProc(
         2508  +UtfToUniCharProc(
  2512   2509       ClientData clientData,	/* TableEncodingData that specifies
  2513   2510   				 * encoding. */
  2514   2511       const char *src,		/* Source string in UTF-8. */
  2515   2512       int srcLen,			/* Source string length in bytes. */
  2516   2513       int flags,			/* Conversion control flags. */
  2517   2514       Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
  2518   2515   				 * information used during a piecewise
................................................................................
  2572   2569   	/*
  2573   2570   	 * Need to handle this in a way that won't cause misalignment by
  2574   2571   	 * casting dst to a Tcl_UniChar. [Bug 1122671]
  2575   2572   	 */
  2576   2573   
  2577   2574   #ifdef WORDS_BIGENDIAN
  2578   2575   #if TCL_UTF_MAX > 4
  2579         -	*dst++ = (*chPtr >> 24);
  2580         -	*dst++ = ((*chPtr >> 16) & 0xFF);
  2581         -	*dst++ = ((*chPtr >> 8) & 0xFF);
  2582         -	*dst++ = (*chPtr & 0xFF);
         2576  +	if (*chPtr <= 0xFFFF) {
         2577  +	    *dst++ = (*chPtr >> 8);
         2578  +	    *dst++ = (*chPtr & 0xFF);
         2579  +	} else {
         2580  +	    *dst++ = ((*chPtr & 0x3) >> 8) | 0xDC;
         2581  +	    *dst++ = (*chPtr & 0xFF);
         2582  +	    *dst++ = (((*chPtr - 0x10000) >> 18) & 0x3) | 0xD8;
         2583  +	    *dst++ = (((*chPtr - 0x10000) >> 10) & 0xFF);
         2584  +	}
  2583   2585   #else
  2584   2586   	*dst++ = (*chPtr >> 8);
  2585   2587   	*dst++ = (*chPtr & 0xFF);
  2586   2588   #endif
  2587   2589   #else
  2588   2590   #if TCL_UTF_MAX > 4
  2589         -	*dst++ = (*chPtr & 0xFF);
  2590         -	*dst++ = ((*chPtr >> 8) & 0xFF);
  2591         -	*dst++ = ((*chPtr >> 16) & 0xFF);
  2592         -	*dst++ = (*chPtr >> 24);
         2591  +	if (*chPtr <= 0xFFFF) {
         2592  +	    *dst++ = (*chPtr & 0xFF);
         2593  +	    *dst++ = (*chPtr >> 8);
         2594  +	} else {
         2595  +	    *dst++ = (((*chPtr - 0x10000) >> 10) & 0xFF);
         2596  +	    *dst++ = (((*chPtr - 0x10000) >> 18) & 0x3) | 0xD8;
         2597  +	    *dst++ = (*chPtr & 0xFF);
         2598  +	    *dst++ = ((*chPtr & 0x3) >> 8) | 0xDC;
         2599  +	}
  2593   2600   #else
  2594   2601   	*dst++ = (*chPtr & 0xFF);
  2595   2602   	*dst++ = (*chPtr >> 8);
  2596   2603   #endif
  2597   2604   #endif
  2598   2605       }
  2599   2606       *srcReadPtr = src - srcStart;

Changes to generic/tclIOUtil.c.

  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/tclInt.h.

  3237   3237   			    const char *trim, int numTrim);
  3238   3238   MODULE_SCOPE int	TclTrimRight(const char *bytes, int numBytes,
  3239   3239   			    const char *trim, int numTrim);
  3240   3240   MODULE_SCOPE const char*TclGetCommandTypeName(Tcl_Command command);
  3241   3241   MODULE_SCOPE void	TclRegisterCommandTypeName(
  3242   3242   			    Tcl_ObjCmdProc *implementationProc,
  3243   3243   			    const char *nameStr);
         3244  +#if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
         3245  +MODULE_SCOPE int TclUtfToWChar(const char *src, WCHAR *chPtr);
         3246  +MODULE_SCOPE char *	TclWCharToUtfDString(const WCHAR *uniStr,
         3247  +			    int uniLength, Tcl_DString *dsPtr);
         3248  +MODULE_SCOPE WCHAR * TclUtfToWCharDString(const char *src,
         3249  +			    int length, Tcl_DString *dsPtr);
         3250  +#else
         3251  +#   define TclUtfToWChar TclUtfToUniChar
         3252  +#   define TclWCharToUtfDString Tcl_UniCharToUtfDString
         3253  +#   define TclUtfToWCharDString Tcl_UtfToUniCharDString
         3254  +#endif
  3244   3255   MODULE_SCOPE int	TclUtfCmp(const char *cs, const char *ct);
  3245   3256   MODULE_SCOPE int	TclUtfCasecmp(const char *cs, const char *ct);
  3246   3257   MODULE_SCOPE int	TclUtfCount(int ch);
  3247   3258   MODULE_SCOPE Tcl_Obj *	TclpNativeToNormalized(ClientData clientData);
  3248   3259   MODULE_SCOPE Tcl_Obj *	TclpFilesystemPathType(Tcl_Obj *pathPtr);
  3249   3260   MODULE_SCOPE int	TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
  3250   3261   			    Tcl_LoadHandle *loadHandle,

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       int 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/tclStrToD.c.

  4573   4573   	if (lsb == -1-shift) {
  4574   4574   
  4575   4575   	    /*
  4576   4576   	     * Round to even
  4577   4577   	     */
  4578   4578   
  4579   4579   	    mp_div_2d(a, -shift, &b, NULL);
  4580         -	    if (mp_isodd(&b)) {
         4580  +	    if (mp_get_bit(&b, 0)) {
  4581   4581   		if (b.sign == MP_ZPOS) {
  4582   4582   		    mp_add_d(&b, 1, &b);
  4583   4583   		} else {
  4584   4584   		    mp_sub_d(&b, 1, &b);
  4585   4585   		}
  4586   4586   	    }
  4587   4587   	} else {

Changes to generic/tclStringObj.c.

  2037   2037   		    numChars = precision;
  2038   2038   		    Tcl_IncrRefCount(segment);
  2039   2039   		    allocSegment = 1;
  2040   2040   		}
  2041   2041   	    }
  2042   2042   	    break;
  2043   2043   	case 'c': {
  2044         -	    char buf[4];
         2044  +	    char buf[TCL_UTF_MAX] = "";
  2045   2045   	    int code, length;
  2046   2046   
  2047   2047   	    if (TclGetIntFromObj(interp, segment, &code) != TCL_OK) {
  2048   2048   		goto error;
  2049   2049   	    }
  2050   2050   	    length = Tcl_UniCharToUtf(code, buf);
  2051   2051   	    if ((code >= 0xD800) && (length < 3)) {

Changes to generic/tclStubInit.c.

    53     53   #undef Tcl_SetLongObj
    54     54   #undef TclpInetNtoa
    55     55   #undef TclWinGetServByName
    56     56   #undef TclWinGetSockOpt
    57     57   #undef TclWinSetSockOpt
    58     58   #undef TclWinNToHS
    59     59   #undef TclStaticPackage
           60  +#undef Tcl_BackgroundError
    60     61   #define TclStaticPackage Tcl_StaticPackage
    61     62   
    62     63   /* See bug 510001: TclSockMinimumBuffers needs plat imp */
    63     64   #if defined(_WIN64) || defined(TCL_NO_DEPRECATED) || TCL_MAJOR_VERSION > 8
    64     65   #   define TclSockMinimumBuffersOld 0
    65     66   #else
    66     67   #define TclSockMinimumBuffersOld sockMinimumBuffersOld
................................................................................
   235    236   
   236    237   char *
   237    238   Tcl_WinUtfToTChar(
   238    239       const char *string,
   239    240       int len,
   240    241       Tcl_DString *dsPtr)
   241    242   {
   242         -#if TCL_UTF_MAX > 4
   243         -    Tcl_UniChar ch = 0;
   244         -    wchar_t *w, *wString;
   245         -    const char *p, *end;
   246         -    int oldLength;
   247         -#endif
   248         -
   249    243       Tcl_DStringInit(dsPtr);
   250    244       if (!string) {
   251    245   	return NULL;
   252    246       }
   253         -#if TCL_UTF_MAX > 4
   254         -
   255         -    if (len < 0) {
   256         -	len = strlen(string);
   257         -    }
   258         -
   259         -    /*
   260         -     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
   261         -     * bytes.
   262         -     */
   263         -
   264         -    oldLength = Tcl_DStringLength(dsPtr);
   265         -
   266         -    Tcl_DStringSetLength(dsPtr,
   267         -	    oldLength + (int) ((len + 1) * sizeof(wchar_t)));
   268         -    wString = (wchar_t *) (Tcl_DStringValue(dsPtr) + oldLength);
   269         -
   270         -    w = wString;
   271         -    p = string;
   272         -    end = string + len - 4;
   273         -    while (p < end) {
   274         -	p += TclUtfToUniChar(p, &ch);
   275         -	if (ch > 0xFFFF) {
   276         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   277         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   278         -	} else {
   279         -	    *w++ = ch;
   280         -	}
   281         -    }
   282         -    end += 4;
   283         -    while (p < end) {
   284         -	if (Tcl_UtfCharComplete(p, end-p)) {
   285         -	    p += TclUtfToUniChar(p, &ch);
   286         -	} else {
   287         -	    ch = UCHAR(*p++);
   288         -	}
   289         -	if (ch > 0xFFFF) {
   290         -	    *w++ = (wchar_t) (0xD800 + ((ch -= 0x10000) >> 10));
   291         -	    *w++ = (wchar_t) (0xDC00 | (ch & 0x3FF));
   292         -	} else {
   293         -	    *w++ = ch;
   294         -	}
   295         -    }
   296         -    *w = '\0';
   297         -    Tcl_DStringSetLength(dsPtr,
   298         -	    oldLength + ((char *) w - (char *) wString));
   299         -
   300         -    return (char *)wString;
   301         -#else
   302         -    return (char *)Tcl_UtfToUniCharDString(string, len, dsPtr);
   303         -#endif
          247  +    return (char *)TclUtfToWCharDString(string, len, dsPtr);
   304    248   }
   305    249   
   306    250   char *
   307    251   Tcl_WinTCharToUtf(
   308    252       const char *string,
   309    253       int len,
   310    254       Tcl_DString *dsPtr)
   311    255   {
   312         -#if TCL_UTF_MAX > 4
   313         -    const wchar_t *w, *wEnd;
   314         -    char *p, *result;
   315         -    int oldLength, blen = 1;
   316         -#endif
   317         -
   318    256       Tcl_DStringInit(dsPtr);
   319    257       if (!string) {
   320    258   	return NULL;
   321    259       }
   322    260       if (len < 0) {
   323    261   	len = wcslen((wchar_t *)string);
   324    262       } else {
   325    263   	len /= 2;
   326    264       }
   327         -#if TCL_UTF_MAX > 4
   328         -    oldLength = Tcl_DStringLength(dsPtr);
   329         -    Tcl_DStringSetLength(dsPtr, oldLength + (len + 1) * 4);
   330         -    result = Tcl_DStringValue(dsPtr) + oldLength;
   331         -
   332         -    p = result;
   333         -    wEnd = (wchar_t *)string + len;
   334         -    for (w = (wchar_t *)string; w < wEnd; ) {
   335         -	if (!blen && ((*w & 0xFC00) != 0xDC00)) {
   336         -	    /* Special case for handling high surrogates. */
   337         -	    p += Tcl_UniCharToUtf(-1, p);
   338         -	}
   339         -	blen = Tcl_UniCharToUtf(*w, p);
   340         -	p += blen;
   341         -	if ((*w >= 0xD800) && (blen < 3)) {
   342         -	    /* Indication that high surrogate is handled */
   343         -	    blen = 0;
   344         -	}
   345         -	w++;
   346         -    }
   347         -    if (!blen) {
   348         -	/* Special case for handling high surrogates. */
   349         -	p += Tcl_UniCharToUtf(-1, p);
   350         -    }
   351         -    Tcl_DStringSetLength(dsPtr, oldLength + (p - result));
   352         -
   353         -    return result;
   354         -#else
   355         -    return Tcl_UniCharToUtfDString((Tcl_UniChar *)string, len, dsPtr);
   356         -#endif
          265  +    return TclWCharToUtfDString((const WCHAR *)string, len, dsPtr);
   357    266   }
   358    267   
   359    268   #if defined(TCL_WIDE_INT_IS_LONG)
   360    269   /* On Cygwin64, long is 64-bit while on Win64 long is 32-bit. Therefore
   361    270    * we have to make sure that all stub entries on Cygwin64 follow the Win64
   362    271    * signature. Tcl 9 must find a better solution, but that cannot be done
   363    272    * without introducing a binary incompatibility.
................................................................................
   499    408   #   define TclpLocaltime_unix 0
   500    409   #   define TclpGmtime_unix 0
   501    410   #   define Tcl_SetExitProc 0
   502    411   #   define Tcl_SetPanicProc 0
   503    412   #   define Tcl_FindExecutable 0
   504    413   #   define Tcl_GetUnicode 0
   505    414   #   define TclOldFreeObj 0
          415  +#   define TclBN_reverse 0
          416  +#   define TclBN_fast_s_mp_mul_digs 0
          417  +#   define TclBN_fast_s_mp_sqr 0
          418  +#   define TclBN_mp_karatsuba_mul 0
          419  +#   define TclBN_mp_karatsuba_sqr 0
          420  +#   define TclBN_mp_toom_mul 0
          421  +#   define TclBN_mp_toom_sqr 0
          422  +#   define TclBN_s_mp_add 0
          423  +#   define TclBN_s_mp_mul_digs 0
          424  +#   define TclBN_s_mp_sqr 0
          425  +#   define TclBN_s_mp_sub 0
   506    426   #else /* TCL_NO_DEPRECATED */
   507    427   #   define Tcl_SeekOld seekOld
   508    428   #   define Tcl_TellOld tellOld
   509    429   #   define TclBackgroundException Tcl_BackgroundException
   510    430   #   define TclSetStartupScript Tcl_SetStartupScript
   511    431   #   define TclGetStartupScript Tcl_GetStartupScript
   512    432   #   define TclCreateNamespace Tcl_CreateNamespace
................................................................................
  1018    938       TclBN_mp_set_long, /* 70 */
  1019    939       TclBN_mp_get_long, /* 71 */
  1020    940       TclBN_mp_get_int, /* 72 */
  1021    941       TclBN_mp_tc_and, /* 73 */
  1022    942       TclBN_mp_tc_or, /* 74 */
  1023    943       TclBN_mp_tc_xor, /* 75 */
  1024    944       TclBN_mp_tc_div_2d, /* 76 */
          945  +    TclBN_mp_get_bit, /* 77 */
  1025    946   };
  1026    947   
  1027    948   static const TclStubHooks tclStubHooks = {
  1028    949       &tclPlatStubs,
  1029    950       &tclIntStubs,
  1030    951       &tclIntPlatStubs
  1031    952   };

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");
................................................................................
  1344   1344   	    }
  1345   1345   	    Tcl_SetIntObj(Tcl_GetObjResult(interp), length);
  1346   1346   	    break;
  1347   1347   	case 10:			/* getunicode */
  1348   1348   	    if (objc != 3) {
  1349   1349   		goto wrongNumArgs;
  1350   1350   	    }
  1351         -	    Tcl_GetUnicodeFromObj(varPtr[varIndex], NULL);
         1351  +	    Tcl_GetUnicode(varPtr[varIndex]);
  1352   1352   	    break;
  1353   1353   	case 11:			/* appendself */
  1354   1354   	    if (objc != 4) {
  1355   1355   		goto wrongNumArgs;
  1356   1356   	    }
  1357   1357   	    if (varPtr[varIndex] == NULL) {
  1358   1358   		SetVarToObj(varPtr, varIndex, Tcl_NewObj());

Changes to generic/tclTomMath.decls.

   174    174   declare 49 {
   175    175       void TclBN_mp_zero(mp_int *a)
   176    176   }
   177    177   
   178    178   # internal routines to libtommath - should not be called but must be
   179    179   # exported to accommodate the "tommath" extension
   180    180   
   181         -declare 50 {
          181  +declare 50 {deprecated {is private function in libtommath}} {
   182    182       void TclBN_reverse(unsigned char *s, int len)
   183    183   }
   184         -declare 51 {
          184  +declare 51 {deprecated {is private function in libtommath}} {
   185    185       int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
   186    186   }
   187         -declare 52 {
          187  +declare 52 {deprecated {is private function in libtommath}} {
   188    188       int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
   189    189   }
   190         -declare 53 {
          190  +declare 53 {deprecated {is private function in libtommath}} {
   191    191       int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
   192    192   }
   193         -declare 54 {
          193  +declare 54 {deprecated {is private function in libtommath}} {
   194    194       int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
   195    195   }
   196         -declare 55 {
          196  +declare 55 {deprecated {is private function in libtommath}} {
   197    197       int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
   198    198   }
   199         -declare 56 {
          199  +declare 56 {deprecated {is private function in libtommath}} {
   200    200       int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
   201    201   }
   202         -declare 57 {
          202  +declare 57 {deprecated {is private function in libtommath}} {
   203    203       int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
   204    204   }
   205         -declare 58 {
          205  +declare 58 {deprecated {is private function in libtommath}} {
   206    206       int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
   207    207   }
   208         -declare 59 {
          208  +declare 59 {deprecated {is private function in libtommath}} {
   209    209       int TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
   210    210   }
   211         -declare 60 {
          211  +declare 60 {deprecated {is private function in libtommath}} {
   212    212       int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
   213    213   }
   214    214   declare 61 {
   215    215       int TclBN_mp_init_set_int(mp_int *a, unsigned long i)
   216    216   }
   217    217   declare 62 {
   218    218       int TclBN_mp_set_int(mp_int *a, unsigned long i)
................................................................................
   263    263   }
   264    264   declare 75 {
   265    265       int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
   266    266   }
   267    267   declare 76 {
   268    268       int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
   269    269   }
          270  +declare 77 {
          271  +    int TclBN_mp_get_bit(const mp_int *a, int b)
          272  +}
   270    273   
   271    274   
   272    275   # Local Variables:
   273    276   # mode: tcl
   274    277   # 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
................................................................................
   268    269   EXTERN int		TclBN_mp_unsigned_bin_size(const mp_int *a);
   269    270   /* 48 */
   270    271   EXTERN int		TclBN_mp_xor(const mp_int *a, const mp_int *b,
   271    272   				mp_int *c);
   272    273   /* 49 */
   273    274   EXTERN void		TclBN_mp_zero(mp_int *a);
   274    275   /* 50 */
   275         -EXTERN void		TclBN_reverse(unsigned char *s, int len);
          276  +TCL_DEPRECATED("is private function in libtommath")
          277  +void			TclBN_reverse(unsigned char *s, int len);
   276    278   /* 51 */
   277         -EXTERN int		TclBN_fast_s_mp_mul_digs(const mp_int *a,
          279  +TCL_DEPRECATED("is private function in libtommath")
          280  +int			TclBN_fast_s_mp_mul_digs(const mp_int *a,
   278    281   				const mp_int *b, mp_int *c, int digs);
   279    282   /* 52 */
   280         -EXTERN int		TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
          283  +TCL_DEPRECATED("is private function in libtommath")
          284  +int			TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
   281    285   /* 53 */
   282         -EXTERN int		TclBN_mp_karatsuba_mul(const mp_int *a,
          286  +TCL_DEPRECATED("is private function in libtommath")
          287  +int			TclBN_mp_karatsuba_mul(const mp_int *a,
   283    288   				const mp_int *b, mp_int *c);
   284    289   /* 54 */
   285         -EXTERN int		TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
          290  +TCL_DEPRECATED("is private function in libtommath")
          291  +int			TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
   286    292   /* 55 */
   287         -EXTERN int		TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
          293  +TCL_DEPRECATED("is private function in libtommath")
          294  +int			TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
   288    295   				mp_int *c);
   289    296   /* 56 */
   290         -EXTERN int		TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
          297  +TCL_DEPRECATED("is private function in libtommath")
          298  +int			TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
   291    299   /* 57 */
   292         -EXTERN int		TclBN_s_mp_add(const mp_int *a, const mp_int *b,
          300  +TCL_DEPRECATED("is private function in libtommath")
          301  +int			TclBN_s_mp_add(const mp_int *a, const mp_int *b,
   293    302   				mp_int *c);
   294    303   /* 58 */
   295         -EXTERN int		TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
          304  +TCL_DEPRECATED("is private function in libtommath")
          305  +int			TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
   296    306   				mp_int *c, int digs);
   297    307   /* 59 */
   298         -EXTERN int		TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
          308  +TCL_DEPRECATED("is private function in libtommath")
          309  +int			TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
   299    310   /* 60 */
   300         -EXTERN int		TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
          311  +TCL_DEPRECATED("is private function in libtommath")
          312  +int			TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
   301    313   				mp_int *c);
   302    314   /* 61 */
   303    315   EXTERN int		TclBN_mp_init_set_int(mp_int *a, unsigned long i);
   304    316   /* 62 */
   305    317   EXTERN int		TclBN_mp_set_int(mp_int *a, unsigned long i);
   306    318   /* 63 */
   307    319   EXTERN int		TclBN_mp_cnt_lsb(const mp_int *a);
................................................................................
   336    348   EXTERN int		TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
   337    349   				mp_int *c);
   338    350   /* 75 */
   339    351   EXTERN int		TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
   340    352   				mp_int *c);
   341    353   /* 76 */
   342    354   EXTERN int		TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c);
          355  +/* 77 */
          356  +EXTERN int		TclBN_mp_get_bit(const mp_int *a, int b);
   343    357   
   344    358   typedef struct TclTomMathStubs {
   345    359       int magic;
   346    360       void *hooks;
   347    361   
   348    362       int (*tclBN_epoch) (void); /* 0 */
   349    363       int (*tclBN_revision) (void); /* 1 */
................................................................................
   391    405       int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
   392    406       int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
   393    407       int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
   394    408       int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
   395    409       int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
   396    410       int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
   397    411       void (*tclBN_mp_zero) (mp_int *a); /* 49 */
   398         -    void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
   399         -    int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
   400         -    int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
   401         -    int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
   402         -    int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
   403         -    int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
   404         -    int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
   405         -    int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
   406         -    int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
   407         -    int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
   408         -    int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
          412  +    TCL_DEPRECATED_API("is private function in libtommath") void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
          413  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
          414  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
          415  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
          416  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
          417  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
          418  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
          419  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
          420  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
          421  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
          422  +    TCL_DEPRECATED_API("is private function in libtommath") int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
   409    423       int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
   410    424       int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
   411    425       int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
   412    426       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
   413    427       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
   414    428       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
   415    429       int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
................................................................................
   418    432       int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
   419    433       unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */
   420    434       unsigned long (*tclBN_mp_get_int) (const mp_int *a); /* 72 */
   421    435       int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
   422    436       int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
   423    437       int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
   424    438       int (*tclBN_mp_tc_div_2d) (const mp_int *a, int b, mp_int *c); /* 76 */
          439  +    int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */
   425    440   } TclTomMathStubs;
   426    441   
   427    442   extern const TclTomMathStubs *tclTomMathStubsPtr;
   428    443   
   429    444   #ifdef __cplusplus
   430    445   }
   431    446   #endif
................................................................................
   586    601   	(tclTomMathStubsPtr->tclBN_mp_tc_and) /* 73 */
   587    602   #define TclBN_mp_tc_or \
   588    603   	(tclTomMathStubsPtr->tclBN_mp_tc_or) /* 74 */
   589    604   #define TclBN_mp_tc_xor \
   590    605   	(tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
   591    606   #define TclBN_mp_tc_div_2d \
   592    607   	(tclTomMathStubsPtr->tclBN_mp_tc_div_2d) /* 76 */
          608  +#define TclBN_mp_get_bit \
          609  +	(tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */
   593    610   
   594    611   #endif /* defined(USE_TCL_STUBS) */
   595    612   
   596    613   /* !END!: Do not edit above this line. */
   597    614   
   598    615   #undef TCL_STORAGE_CLASS
   599    616   #define TCL_STORAGE_CLASS DLLIMPORT
   600    617   
   601    618   #endif /* _TCLINTDECLS */

Changes to generic/tclUtf.c.

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

Changes to generic/tclUtil.c.

  2298   2298   		 * character
  2299   2299   		 */
  2300   2300   
  2301   2301   		if ((p != '[') && (p != '?') && (p != '\\')) {
  2302   2302   		    if (nocase) {
  2303   2303   			while (*str) {
  2304   2304   			    charLen = TclUtfToUniChar(str, &ch1);
  2305         -			    if (ch2==ch1 || ch2==Tcl_UniCharToLower(ch1)) {
         2305  +			    if (ch2==ch1 || ch2==(Tcl_UniChar)Tcl_UniCharToLower(ch1)) {
  2306   2306   				break;
  2307   2307   			    }
  2308   2308   			    str += charLen;
  2309   2309   			}
  2310   2310   		    } else {
  2311   2311   			/*
  2312   2312   			 * There's no point in trying to make this code

Changes to generic/tclZipfs.c.

  4843   4843    *-------------------------------------------------------------------------
  4844   4844    */
  4845   4845   
  4846   4846   int
  4847   4847   TclZipfs_AppHook(
  4848   4848       int *argcPtr,		/* Pointer to argc */
  4849   4849   #ifdef _WIN32
  4850         -    TCHAR
         4850  +    WCHAR
  4851   4851   #else /* !_WIN32 */
  4852   4852       char
  4853   4853   #endif /* _WIN32 */
  4854   4854       ***argvPtr)			/* Pointer to argv */
  4855   4855   {
  4856   4856       char *archive;
  4857   4857   

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 \
................................................................................
  1527   1527   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_exch.c
  1528   1528   
  1529   1529   bn_mp_expt_d.o: $(TOMMATH_DIR)/bn_mp_expt_d.c $(MATHHDRS)
  1530   1530   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d.c
  1531   1531   
  1532   1532   bn_mp_expt_d_ex.o: $(TOMMATH_DIR)/bn_mp_expt_d_ex.c $(MATHHDRS)
  1533   1533   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d_ex.c
         1534  +
         1535  +bn_mp_get_bit.o: $(TOMMATH_DIR)/bn_mp_get_bit.c $(MATHHDRS)
         1536  +	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_bit.c
  1534   1537   
  1535   1538   bn_mp_get_int.o: $(TOMMATH_DIR)/bn_mp_get_int.c $(MATHHDRS)
  1536   1539   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_int.c
  1537   1540   
  1538   1541   bn_mp_get_long.o: $(TOMMATH_DIR)/bn_mp_get_long.c $(MATHHDRS)
  1539   1542   	$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_long.c
  1540   1543   

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   	    ckfree(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   	ckfree(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 = ckalloc(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       int len,			/* Source string length in bytes, or -1 for
   470    470   				 * 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       int len,			/* Source string length in bytes, or -1 for
   542    485   				 * 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 < 0) {
   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;
................................................................................
   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);
................................................................................
  1520   1520   	 * It is hidden. However there is a bug on some Windows OSes in which
  1521   1521   	 * root volumes (drives) formatted as NTFS are declared hidden when
  1522   1522   	 * they are not (and cannot be).
  1523   1523   	 *
  1524   1524   	 * We test for, and fix that case, here.
  1525   1525   	 */
  1526   1526   
  1527         -	const char *str = TclGetString(fileName);
  1528         -	size_t len = fileName->length;
         1527  +	int len;
         1528  +	const char *str = TclGetStringFromObj(fileName, &len);
  1529   1529   
  1530   1530   	if (len < 4) {
  1531   1531   	    if (len == 0) {
  1532   1532   		/*
  1533   1533   		 * Not sure if this is possible, but we pass it on anyway.
  1534   1534   		 */
  1535   1535   	    } else if (len == 1 && (str[0] == '/' || str[0] == '\\')) {
................................................................................
  1606   1606        */
  1607   1607   
  1608   1608       Tcl_IncrRefCount(splitPath);
  1609   1609   
  1610   1610       for (i = 0; i < pathc; i++) {
  1611   1611   	Tcl_Obj *elt;
  1612   1612   	char *pathv;
         1613  +	int length;
  1613   1614   
  1614   1615   	Tcl_ListObjIndex(NULL, splitPath, i, &elt);
  1615   1616   
  1616         -	pathv = TclGetString(elt);
  1617         -	if ((pathv[0] == '/') || ((elt->length == 3) && (pathv[1] == ':'))
         1617  +	pathv = TclGetStringFromObj(elt, &length);
         1618  +	if ((pathv[0] == '/') || ((length == 3) && (pathv[1] == ':'))
  1618   1619   		|| (strcmp(pathv, ".") == 0) || (strcmp(pathv, "..") == 0)) {
  1619   1620   	    /*
  1620   1621   	     * Handle "/", "//machine/export", "c:/", "." or ".." by just
  1621   1622   	     * copying the string literally.  Uppercase the drive letter, just
  1622   1623   	     * because it looks better under Windows to do so.
  1623   1624   	     */
  1624   1625   
................................................................................
  1631   1632   	     */
  1632   1633   
  1633   1634   	    pathv[0] = (char) Tcl_UniCharToUpper(UCHAR(pathv[0]));
  1634   1635   	} else {
  1635   1636   	    Tcl_Obj *tempPath;
  1636   1637   	    Tcl_DString ds;
  1637   1638   	    Tcl_DString dsTemp;
  1638         -	    const TCHAR *nativeName;
         1639  +	    const WCHAR *nativeName;
  1639   1640   	    const char *tempString;
  1640   1641   	    WIN32_FIND_DATA data;
  1641   1642   	    HANDLE handle;
  1642   1643   	    DWORD attr;
  1643   1644   
  1644   1645   	    tempPath = Tcl_FSJoinPath(splitPath, i+1);
  1645   1646   	    Tcl_IncrRefCount(tempPath);
  1646   1647   
  1647   1648   	    /*
  1648   1649   	     * We'd like to call Tcl_FSGetNativePath(tempPath) but that is
  1649   1650   	     * likely to lead to infinite loops.
  1650   1651   	     */
  1651   1652   
  1652         -	    tempString = TclGetString(tempPath);
  1653         -	    nativeName = Tcl_WinUtfToTChar(tempString, tempPath->length, &ds);
         1653  +	    tempString = TclGetStringFromObj(tempPath, &length);
         1654  +	    nativeName = Tcl_WinUtfToTChar(tempString, length, &ds);
  1654   1655   	    Tcl_DecrRefCount(tempPath);
  1655   1656   	    handle = FindFirstFile(nativeName, &data);
  1656   1657   	    if (handle == INVALID_HANDLE_VALUE) {
  1657   1658   		/*
  1658   1659   		 * FindFirstFile() doesn't like root directories. We would
  1659   1660   		 * only get a root directory here if the caller specified "c:"
  1660   1661   		 * or "c:." and the current directory on the drive was the
................................................................................
  1678   1679   	    nativeName = data.cAlternateFileName;
  1679   1680   	    if (longShort) {
  1680   1681   		if (data.cFileName[0] != '\0') {
  1681   1682   		    nativeName = data.cFileName;
  1682   1683   		}
  1683   1684   	    } else {
  1684   1685   		if (data.cAlternateFileName[0] == '\0') {
  1685         -		    nativeName = (TCHAR *) data.cFileName;
         1686  +		    nativeName = (WCHAR *) data.cFileName;
  1686   1687   		}
  1687   1688   	    }
  1688   1689   
  1689   1690   	    /*
  1690   1691   	     * Purify reports a extraneous UMR in Tcl_WinTCharToUtf() trying
  1691   1692   	     * to dereference nativeName as a Unicode string. I have proven to
  1692   1693   	     * myself that purify is wrong by running the following example
................................................................................
  1824   1825       Tcl_Interp *interp,		/* The interp we are using for errors. */
  1825   1826       int objIndex,		/* The index of the attribute. */
  1826   1827       Tcl_Obj *fileName,		/* The name of the file. */
  1827   1828       Tcl_Obj *attributePtr)	/* The new value of the attribute. */
  1828   1829   {
  1829   1830       DWORD fileAttributes, old;
  1830   1831       int yesNo, result;
  1831         -    const TCHAR *nativeName;
         1832  +    const WCHAR *nativeName;
  1832   1833   
  1833   1834       nativeName = Tcl_FSGetNativePath(fileName);
  1834   1835       fileAttributes = old = GetFileAttributes(nativeName);
  1835   1836   
  1836   1837       if (fileAttributes == 0xffffffff) {
  1837   1838   	StatError(interp, fileName);
  1838   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 TCL_NORETURN 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.
................................................................................
   909    909       Tcl_Obj *resultPtr,		/* List object to lappend results. */
   910    910       Tcl_Obj *pathPtr,		/* Contains path to directory to search. */
   911    911       const char *pattern,	/* Pattern to match against. */
   912    912       Tcl_GlobTypeData *types)	/* Object containing list of acceptable types.
   913    913   				 * May be NULL. In particular the directory
   914    914   				 * flag is very important. */
   915    915   {
   916         -    const TCHAR *native;
          916  +    const WCHAR *native;
   917    917   
   918    918       if (types != NULL && types->type == TCL_GLOB_TYPE_MOUNT) {
   919    919   	/*
   920    920   	 * The native filesystem never adds mounts.
   921    921   	 */
   922    922   
   923    923   	return TCL_OK;
................................................................................
   927    927   	Tcl_Obj *norm = Tcl_FSGetNormalizedPath(NULL, pathPtr);
   928    928   
   929    929   	if (norm != NULL) {
   930    930   	    /*
   931    931   	     * Match a single file directly.
   932    932   	     */
   933    933   
          934  +	    int len;
   934    935   	    DWORD attr;
   935    936   	    WIN32_FILE_ATTRIBUTE_DATA data;
   936         -	    const char *str = TclGetString(norm);
          937  +	    const char *str = TclGetStringFromObj(norm, &len);
   937    938   
   938    939   	    native = Tcl_FSGetNativePath(pathPtr);
   939    940   
   940    941   	    if (GetFileAttributesEx(native,
   941    942   		    GetFileExInfoStandard, &data) != TRUE) {
   942    943   		return TCL_OK;
   943    944   	    }
   944    945   	    attr = data.dwFileAttributes;
   945    946   
   946         -	    if (NativeMatchType(WinIsDrive(str,norm->length), attr, native, types)) {
          947  +	    if (NativeMatchType(WinIsDrive(str,len), attr, native, types)) {
   947    948   		Tcl_ListObjAppendElement(interp, resultPtr, pathPtr);
   948    949   	    }
   949    950   	}
   950    951   	return TCL_OK;
   951    952       } else {
   952    953   	DWORD attr;
   953    954   	HANDLE handle;
   954    955   	WIN32_FIND_DATA data;
   955    956   	const char *dirName;	/* UTF-8 dir name, later with pattern
   956    957   				 * appended. */
   957         -	size_t dirLength;
          958  +	int dirLength;
   958    959   	int matchSpecialDots;
   959    960   	Tcl_DString ds;		/* Native encoding of dir, also used
   960    961   				 * temporarily for other things. */
   961    962   	Tcl_DString dsOrig;	/* UTF-8 encoding of dir. */
   962    963   	Tcl_Obj *fileNamePtr;
   963    964   	char lastChar;
   964    965   
................................................................................
   989    990   
   990    991   	/*
   991    992   	 * Build up the directory name for searching, including a trailing
   992    993   	 * directory separator.
   993    994   	 */
   994    995   
   995    996   	Tcl_DStringInit(&dsOrig);
   996         -	dirName = TclGetString(fileNamePtr);
   997         -	dirLength = fileNamePtr->length;
          997  +	dirName = TclGetStringFromObj(fileNamePtr, &dirLength);
   998    998   	Tcl_DStringAppend(&dsOrig, dirName, dirLength);
   999    999   
  1000   1000   	lastChar = dirName[dirLength -1];
  1001   1001   	if ((lastChar != '\\') && (lastChar != '/') && (lastChar != ':')) {
  1002   1002   	    TclDStringAppendLiteral(&dsOrig, "/");
  1003   1003   	    dirLength++;
  1004   1004   	}
................................................................................
  1309   1309    */
  1310   1310   
  1311   1311   static int
  1312   1312   NativeMatchType(
  1313   1313       int isDrive,		/* Is this a drive. */
  1314   1314       DWORD attr,			/* We already know the attributes for the
  1315   1315   				 * file. */
  1316         -    const TCHAR *nativeName,	/* Native path to check. */
         1316  +    const WCHAR *nativeName,	/* Native path to check. */
  1317   1317       Tcl_GlobTypeData *types)	/* Type description to match against. */
  1318   1318   {
  1319   1319       /*
  1320   1320        * 'attr' represents the attributes of the file, but we only want to
  1321   1321        * retrieve this info if it is absolutely necessary because it is an
  1322   1322        * expensive call. Unfortunately, to deal with hidden files properly, we
  1323   1323        * must always retrieve it.
................................................................................
  1461   1461   		rc = 1;
  1462   1462   		result = Tcl_DStringValue(bufferPtr);
  1463   1463   	    }
  1464   1464   	}
  1465   1465   	Tcl_DStringFree(&ds);
  1466   1466       } else {
  1467   1467   	Tcl_DStringInit(&ds);
  1468         -	wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds);
         1468  +	wName = TclUtfToWCharDString(domain + 1, -1, &ds);
  1469   1469   	rc = NetGetDCName(NULL, wName, (LPBYTE *) &wDomain);
  1470   1470   	Tcl_DStringFree(&ds);
  1471   1471   	nameLen = domain - name;
  1472   1472       }
  1473   1473       if (rc == 0) {
  1474   1474   	Tcl_DStringInit(&ds);
  1475         -	wName = Tcl_UtfToUniCharDString(name, nameLen, &ds);
         1475  +	wName = TclUtfToWCharDString(name, nameLen, &ds);
  1476   1476   	while (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) &uiPtr) != 0) {
  1477   1477   	    /*
  1478   1478   	     * user does not exists - if domain was not specified,
  1479   1479   	     * try again using current domain.
  1480   1480   	     */
  1481   1481   	    rc = 1;
  1482   1482   	    if (domain != NULL) break;
................................................................................
  1486   1486   	    domain = INT2PTR(-1); /* repeat once */
  1487   1487   	}
  1488   1488   	if (rc == 0) {
  1489   1489   	    DWORD i, size = MAX_PATH;
  1490   1490   	    wHomeDir = uiPtr->usri1_home_dir;
  1491   1491   	    if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) {
  1492   1492   		size = lstrlenW(wHomeDir);
  1493         -		Tcl_UniCharToUtfDString(wHomeDir, size, bufferPtr);
         1493  +		TclWCharToUtfDString(wHomeDir, size, bufferPtr);
  1494   1494   	    } else {
  1495   1495   		/*
  1496   1496   		 * User exists but has no home dir. Return
  1497   1497   		 * "{GetProfilesDirectory}/<user>".
  1498   1498   		 */
  1499   1499   		GetProfilesDirectoryW(buf, &size);
  1500         -		Tcl_UniCharToUtfDString(buf, size-1, bufferPtr);
         1500  +		TclWCharToUtfDString(buf, size-1, bufferPtr);
  1501   1501   		Tcl_DStringAppend(bufferPtr, "/", 1);
  1502   1502   		Tcl_DStringAppend(bufferPtr, name, nameLen);
  1503   1503   	    }
  1504   1504   	    result = Tcl_DStringValue(bufferPtr);
  1505         -	    /* be sure we returns normalized path */
         1505  +	    /* be sure we return normalized path */
  1506   1506   	    for (i = 0; i < size; ++i){
  1507   1507   		if (result[i] == '\\') result[i] = '/';
  1508   1508   	    }
  1509   1509   	    NetApiBufferFree((void *) uiPtr);
  1510   1510   	}
  1511   1511   	Tcl_DStringFree(&ds);
  1512   1512       }
................................................................................
  1558   1558    *	See access documentation.
  1559   1559    *
  1560   1560    *---------------------------------------------------------------------------
  1561   1561    */
  1562   1562   
  1563   1563   static int
  1564   1564   NativeAccess(
  1565         -    const TCHAR *nativePath,	/* Path of file to access, native encoding. */
         1565  +    const WCHAR *nativePath,	/* Path of file to access, native encoding. */
  1566   1566       int mode)			/* Permission setting. */
  1567   1567   {
  1568   1568       DWORD attr;
  1569   1569   
  1570   1570       attr = GetFileAttributes(nativePath);
  1571   1571   
  1572   1572       if (attr == INVALID_FILE_ATTRIBUTES) {
................................................................................
  1820   1820    *	1 = executable, 0 = not.
  1821   1821    *
  1822   1822    *----------------------------------------------------------------------
  1823   1823    */
  1824   1824   
  1825   1825   static int
  1826   1826   NativeIsExec(
  1827         -    const TCHAR *path)
         1827  +    const WCHAR *path)
  1828   1828   {
  1829         -    int len = _tcslen(path);
         1829  +    int len = wcslen(path);
  1830   1830   
  1831   1831       if (len < 5) {
  1832   1832   	return 0;
  1833   1833       }
  1834   1834   
  1835   1835       if (path[len-4] != '.') {
  1836   1836   	return 0;
  1837   1837       }
  1838   1838   
  1839   1839       path += len-3;
  1840         -    if ((_tcsicmp(path, TEXT("exe")) == 0)
  1841         -	    || (_tcsicmp(path, TEXT("com")) == 0)
  1842         -	    || (_tcsicmp(path, TEXT("cmd")) == 0)
  1843         -	    || (_tcsicmp(path, TEXT("cmd")) == 0)
  1844         -	    || (_tcsicmp(path, TEXT("bat")) == 0)) {
         1840  +    if ((wcsicmp(path, L"exe") == 0)
         1841  +	    || (wcsicmp(path, L"com") == 0)
         1842  +	    || (wcsicmp(path, L"cmd") == 0)
         1843  +	    || (wcsicmp(path, L"cmd") == 0)
         1844  +	    || (wcsicmp(path, L"bat") == 0)) {
  1845   1845   	return 1;
  1846   1846       }
  1847   1847       return 0;
  1848   1848   }
  1849   1849   
  1850   1850   /*
  1851   1851    *----------------------------------------------------------------------
................................................................................
  1864   1864    */
  1865   1865   
  1866   1866   int
  1867   1867   TclpObjChdir(
  1868   1868       Tcl_Obj *pathPtr)	/* Path to new working directory. */
  1869   1869   {
  1870   1870       int result;
  1871         -    const TCHAR *nativePath;
         1871  +    const WCHAR *nativePath;
  1872   1872   
  1873   1873       nativePath = Tcl_FSGetNativePath(pathPtr);
  1874   1874   
  1875   1875       if (!nativePath) {
  1876   1876   	return -1;
  1877   1877       }
  1878   1878       result = SetCurrentDirectory(nativePath);
................................................................................
  1908   1908   
  1909   1909   const char *
  1910   1910   TclpGetCwd(
  1911   1911       Tcl_Interp *interp,		/* If non-NULL, used for error reporting. */
  1912   1912       Tcl_DString *bufferPtr)	/* Uninitialized or free DString filled with
  1913   1913   				 * name of current directory. */
  1914   1914   {
  1915         -    TCHAR buffer[MAX_PATH];
         1915  +    WCHAR buffer[MAX_PATH];
  1916   1916       char *p;
  1917   1917       WCHAR *native;
  1918   1918   
  1919   1919       if (GetCurrentDirectory(MAX_PATH, buffer) == 0) {
  1920   1920   	TclWinConvertError(GetLastError());
  1921   1921   	if (interp != NULL) {
  1922   1922   	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
................................................................................
  1931   1931        */
  1932   1932   
  1933   1933       native = (WCHAR *) buffer;
  1934   1934       if ((native[0] != '\0') && (native[1] == ':')
  1935   1935   	    && (native[2] == '\\') && (native[3] == '\\')) {
  1936   1936   	native += 2;
  1937   1937       }
  1938         -    Tcl_WinTCharToUtf((TCHAR *) native, -1, bufferPtr);
         1938  +    Tcl_WinTCharToUtf(native, -1, bufferPtr);
  1939   1939   
  1940   1940       /*
  1941   1941        * Convert to forward slashes for easier use in scripts.
  1942   1942        */
  1943   1943   
  1944   1944       for (p = Tcl_DStringValue(bufferPtr); *p != '\0'; p++) {
  1945   1945   	if (*p == '\\') {
................................................................................
  1986   1986    *	See stat documentation.
  1987   1987    *
  1988   1988    *----------------------------------------------------------------------
  1989   1989    */
  1990   1990   
  1991   1991   static int
  1992   1992   NativeStat(
  1993         -    const TCHAR *nativePath,	/* Path of file to stat */
         1993  +    const WCHAR *nativePath,	/* Path of file to stat */
  1994   1994       Tcl_StatBuf *statPtr,	/* Filled with results of stat call. */
  1995   1995       int checkLinks)		/* If non-zero, behave like 'lstat' */
  1996   1996   {
  1997   1997       DWORD attr;
  1998   1998       int dev, nlink = 1;
  1999   1999       unsigned short mode;
  2000   2000       unsigned int inode = 0;
................................................................................
  2127   2127    *	Calculate just the 'st_dev' field of a 'stat' structure.
  2128   2128    *
  2129   2129    *----------------------------------------------------------------------
  2130   2130    */
  2131   2131   
  2132   2132   static int
  2133   2133   NativeDev(
  2134         -    const TCHAR *nativePath)	/* Full path of file to stat */
         2134  +    const WCHAR *nativePath)	/* Full path of file to stat */
  2135   2135   {
  2136   2136       int dev;
  2137   2137       Tcl_DString ds;
  2138         -    TCHAR nativeFullPath[MAX_PATH];
  2139         -    TCHAR *nativePart;
         2138  +    WCHAR nativeFullPath[MAX_PATH];
         2139  +    WCHAR *nativePart;
  2140   2140       const char *fullPath;
  2141   2141   
  2142   2142       GetFullPathName(nativePath, MAX_PATH, nativeFullPath, &nativePart);
  2143   2143       fullPath = Tcl_WinTCharToUtf(nativeFullPath, -1, &ds);
  2144   2144   
  2145   2145       if ((fullPath[0] == '\\') && (fullPath[1] == '\\')) {
  2146   2146   	const char *p;
  2147   2147   	DWORD dw;
  2148         -	const TCHAR *nativeVol;
         2148  +	const WCHAR *nativeVol;
  2149   2149   	Tcl_DString volString;
  2150   2150   
  2151   2151   	p = strchr(fullPath + 2, '\\');
  2152   2152   	p = strchr(p + 1, '\\');
  2153   2153   	if (p == NULL) {
  2154   2154   	    /*
  2155   2155   	     * Add terminating backslash to fullpath or GetVolumeInformation()
................................................................................
  2303   2303    *----------------------------------------------------------------------
  2304   2304    */
  2305   2305   
  2306   2306   ClientData
  2307   2307   TclpGetNativeCwd(
  2308   2308       ClientData clientData)
  2309   2309   {
  2310         -    TCHAR buffer[MAX_PATH];
         2310  +    WCHAR buffer[MAX_PATH];
  2311   2311   
  2312   2312       if (GetCurrentDirectory(MAX_PATH, buffer) == 0) {
  2313   2313   	TclWinConvertError(GetLastError());
  2314   2314   	return NULL;
  2315   2315       }
  2316   2316   
  2317   2317       if (clientData != NULL) {
  2318         -	if (_tcscmp((const TCHAR*)clientData, buffer) == 0) {
         2318  +	if (wcscmp((const WCHAR*)clientData, buffer) == 0) {
  2319   2319   	    return clientData;
  2320   2320   	}
  2321   2321       }
  2322   2322   
  2323   2323       return TclNativeDupInternalRep(buffer);
  2324   2324   }
  2325   2325   
................................................................................
  2352   2352   TclpObjLink(
  2353   2353       Tcl_Obj *pathPtr,
  2354   2354       Tcl_Obj *toPtr,
  2355   2355       int linkAction)
  2356   2356   {
  2357   2357       if (toPtr != NULL) {
  2358   2358   	int res;
  2359         -	const TCHAR *LinkTarget;
  2360         -	const TCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
         2359  +	const WCHAR *LinkTarget;
         2360  +	const WCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
  2361   2361   	Tcl_Obj *normalizedToPtr = Tcl_FSGetNormalizedPath(NULL, toPtr);
  2362   2362   
  2363   2363   	if (normalizedToPtr == NULL) {
  2364   2364   	    return NULL;
  2365   2365   	}
  2366   2366   
  2367   2367   	LinkTarget = Tcl_FSGetNativePath(normalizedToPtr);
................................................................................
  2372   2372   	res = WinLink(LinkSource, LinkTarget, linkAction);
  2373   2373   	if (res == 0) {
  2374   2374   	    return toPtr;
  2375   2375   	} else {
  2376   2376   	    return NULL;
  2377   2377   	}
  2378   2378       } else {
  2379         -	const TCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
         2379  +	const WCHAR *LinkSource = Tcl_FSGetNativePath(pathPtr);
  2380   2380   
  2381   2381   	if (LinkSource == NULL) {
  2382   2382   	    return NULL;
  2383   2383   	}
  2384   2384   	return WinReadLink(LinkSource);
  2385   2385       }
  2386   2386   }
................................................................................
  2406   2406   
  2407   2407   Tcl_Obj *
  2408   2408   TclpFilesystemPathType(
  2409   2409       Tcl_Obj *pathPtr)
  2410   2410   {
  2411   2411   #define VOL_BUF_SIZE 32
  2412   2412       int found;
  2413         -    TCHAR volType[VOL_BUF_SIZE];
         2413  +    WCHAR volType[VOL_BUF_SIZE];
  2414   2414       char *firstSeparator;
  2415   2415       const char *path;
  2416   2416       Tcl_Obj *normPath = Tcl_FSGetNormalizedPath(NULL, pathPtr);
  2417   2417   
  2418   2418       if (normPath == NULL) {
  2419   2419   	return NULL;
  2420   2420       }
................................................................................
  2507   2507   
  2508   2508   	if ((cur=='/' || cur==0) && (path != currentPathEndPosition)) {
  2509   2509   	    /*
  2510   2510   	     * Reached directory separator, or end of string.
  2511   2511   	     */
  2512   2512   
  2513   2513   	    WIN32_FILE_ATTRIBUTE_DATA data;
  2514         -	    const TCHAR *nativePath = Tcl_WinUtfToTChar(path,
         2514  +	    const WCHAR *nativePath = Tcl_WinUtfToTChar(path,
  2515   2515   		    currentPathEndPosition - path, &ds);
  2516   2516   
  2517   2517   	    if (GetFileAttributesEx(nativePath,
  2518   2518   		    GetFileExInfoStandard, &data) != TRUE) {
  2519   2519   		/*
  2520   2520   		 * File doesn't exist.
  2521   2521   		 */
................................................................................
  2650   2650   		     * path like that. However, to be nice we at least
  2651   2651   		     * don't mangle the path - we just add the dots as a
  2652   2652   		     * path segment and continue.
  2653   2653   		     */
  2654   2654   
  2655   2655   		    Tcl_DStringAppend(&dsNorm, ((const char *)nativePath)
  2656   2656   			    + Tcl_DStringLength(&ds)
  2657         -			    - (dotLen * sizeof(TCHAR)),
  2658         -			    (int)(dotLen * sizeof(TCHAR)));
         2657  +			    - (dotLen * sizeof(WCHAR)),
         2658  +			    dotLen * sizeof(WCHAR));
  2659   2659   		} else {
  2660   2660   		    /*
  2661   2661   		     * Normal path.
  2662   2662   		     */
  2663   2663   
  2664   2664   		    WIN32_FIND_DATAW fData;
  2665   2665   		    HANDLE handle;
................................................................................
  2709   2709   #ifdef TclNORM_LONG_PATH
  2710   2710   	/*
  2711   2711   	 * Convert the entire known path to long form.
  2712   2712   	 */
  2713   2713   
  2714   2714   	if (1) {
  2715   2715   	    WCHAR wpath[MAX_PATH];
  2716         -	    const TCHAR *nativePath =
         2716  +	    const WCHAR *nativePath =
  2717   2717   		    Tcl_WinUtfToTChar(path, lastValidPathEnd - path, &ds);
  2718   2718   	    DWORD wpathlen = GetLongPathNameProc(nativePath,
  2719         -		    (TCHAR *) wpath, MAX_PATH);
         2719  +		    (WCHAR *) wpath, MAX_PATH);
  2720   2720   
  2721   2721   	    /*
  2722   2722   	     * We have to make the drive letter uppercase.
  2723   2723   	     */
  2724   2724   
  2725   2725   	    if (wpath[0] >= L'a') {
  2726   2726   		wpath[0] -= (L'a' - L'A');
................................................................................
  2740   2740       if (lastValidPathEnd != NULL) {
  2741   2741   	/*
  2742   2742   	 * Concatenate the normalized string in dsNorm with the tail of the
  2743   2743   	 * path which we didn't recognise. The string in dsNorm is in the
  2744   2744   	 * native encoding, so we have to convert it to Utf.
  2745   2745   	 */
  2746   2746   
  2747         -	Tcl_WinTCharToUtf((const TCHAR *) Tcl_DStringValue(&dsNorm),
         2747  +	Tcl_WinTCharToUtf((const WCHAR *) Tcl_DStringValue(&dsNorm),
  2748   2748   		Tcl_DStringLength(&dsNorm), &ds);
  2749   2749   	nextCheckpoint = Tcl_DStringLength(&ds);
  2750   2750   	if (*lastValidPathEnd != 0) {
  2751   2751   	    /*
  2752   2752   	     * Not the end of the string.
  2753   2753   	     */
  2754   2754   
         2755  +	    int len;
  2755   2756   	    char *path;
  2756   2757   	    Tcl_Obj *tmpPathPtr;
  2757   2758   
  2758   2759   	    tmpPathPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds),
  2759   2760   		    nextCheckpoint);
  2760   2761   	    Tcl_AppendToObj(tmpPathPtr, lastValidPathEnd, -1);
  2761         -	    path = TclGetString(tmpPathPtr);
  2762         -	    Tcl_SetStringObj(pathPtr, path, tmpPathPtr->length);
         2762  +	    path = TclGetStringFromObj(tmpPathPtr, &len);
         2763  +	    Tcl_SetStringObj(pathPtr, path, len);
  2763   2764   	    Tcl_DecrRefCount(tmpPathPtr);
  2764   2765   	} else {
  2765   2766   	    /*
  2766   2767   	     * End of string was reached above.
  2767   2768   	     */
  2768   2769   
  2769   2770   	    Tcl_SetStringObj(pathPtr, Tcl_DStringValue(&ds), nextCheckpoint);
................................................................................
  2838   2839   	 */
  2839   2840       } else {
  2840   2841   	/*
  2841   2842   	 * Path of form C:foo/bar, but this only makes sense if the cwd is
  2842   2843   	 * also on drive C.
  2843   2844   	 */
  2844   2845   
  2845         -	const char *drive = TclGetString(useThisCwd);
  2846         -	size_t cwdLen = useThisCwd->length;
         2846  +	int cwdLen;
         2847  +	const char *drive = TclGetStringFromObj(useThisCwd, &cwdLen);
  2847   2848   	char drive_cur = path[0];
  2848   2849   
  2849   2850   	if (drive_cur >= 'a') {
  2850   2851   	    drive_cur -= ('a' - 'A');
  2851   2852   	}
  2852   2853   	if (drive[0] == drive_cur) {
  2853   2854   	    absolutePath = Tcl_DuplicateObj(useThisCwd);
................................................................................
  2915   2916       ClientData clientData)
  2916   2917   {
  2917   2918       Tcl_DString ds;
  2918   2919       Tcl_Obj *objPtr;
  2919   2920       int len;
  2920   2921       char *copy, *p;
  2921   2922   
  2922         -    Tcl_WinTCharToUtf((const TCHAR *) clientData, -1, &ds);
         2923  +    Tcl_WinTCharToUtf((const WCHAR *) clientData, -1, &ds);
  2923   2924       copy = Tcl_DStringValue(&ds);
  2924   2925       len = Tcl_DStringLength(&ds);
  2925   2926   
  2926   2927       /*
  2927   2928        * Certain native path representations on Windows have this special prefix
  2928   2929        * to indicate that they are to be treated specially. For example
  2929   2930        * extremely long paths, or symlinks.
................................................................................
  2974   2975   ClientData
  2975   2976   TclNativeCreateNativeRep(
  2976   2977       Tcl_Obj *pathPtr)
  2977   2978   {
  2978   2979       WCHAR *nativePathPtr = NULL;
  2979   2980       const char *str;
  2980   2981       Tcl_Obj *validPathPtr;
  2981         -    size_t len;
         2982  +    int len;
  2982   2983       WCHAR *wp;
  2983   2984   
  2984   2985       if (TclFSCwdIsNative()) {
  2985   2986   	/*
  2986   2987   	 * The cwd is native, which means we can use the translated path
  2987   2988   	 * without worrying about normalization (this will also usually be
  2988   2989   	 * shorter so the utf-to-external conversion will be somewhat faster).
................................................................................
  3002   3003   	if (validPathPtr == NULL) {
  3003   3004   	    return NULL;
  3004   3005   	}
  3005   3006   	/* validPathPtr returned from Tcl_FSGetNormalizedPath is owned by Tcl, so incr refCount here */
  3006   3007   	Tcl_IncrRefCount(validPathPtr);
  3007   3008       }
  3008   3009   
  3009         -    str = Tcl_GetString(validPathPtr);
  3010         -    len = validPathPtr->length;
         3010  +    str = Tcl_GetStringFromObj(validPathPtr, &len);
  3011   3011   
  3012         -    if (strlen(str)!=(unsigned int)len) {
         3012  +    if (strlen(str)!=(size_t)len) {
  3013   3013   	/* String contains NUL-bytes. This is invalid. */
  3014   3014   	goto done;
  3015   3015       }
  3016   3016       /* For a reserved device, strip a possible postfix ':' */
  3017   3017       len = WinIsReserved(str);
  3018   3018       if (len == 0) {
  3019   3019   	/* Let MultiByteToWideChar check for other invalid sequences, like
................................................................................
  3108   3108       char *copy;
  3109   3109       size_t len;
  3110   3110   
  3111   3111       if (clientData == NULL) {
  3112   3112   	return NULL;
  3113   3113       }
  3114   3114   
  3115         -    len = sizeof(TCHAR) * (_tcslen((const TCHAR *) clientData) + 1);
         3115  +    len = sizeof(WCHAR) * (wcslen((const WCHAR *) clientData) + 1);
  3116   3116   
  3117   3117       copy = ckalloc(len);
  3118   3118       memcpy(copy, clientData, len);
  3119   3119       return copy;
  3120   3120   }
  3121   3121   
  3122   3122   /*
................................................................................
  3139   3139   int
  3140   3140   TclpUtime(
  3141   3141       Tcl_Obj *pathPtr,		/* File to modify */
  3142   3142       struct utimbuf *tval)	/* New modification date structure */
  3143   3143   {
  3144   3144       int res = 0;
  3145   3145       HANDLE fileHandle;
  3146         -    const TCHAR *native;
         3146  +    const WCHAR *native;
  3147   3147       DWORD attr = 0;
  3148   3148       DWORD flags = FILE_ATTRIBUTE_NORMAL;
  3149   3149       FILETIME lastAccessTime, lastModTime;
  3150   3150   
  3151   3151       FromCTime(tval->actime, &lastAccessTime);
  3152   3152       FromCTime(tval->modtime, &lastModTime);
  3153   3153   
................................................................................
  3190   3190    *---------------------------------------------------------------------------
  3191   3191    */
  3192   3192   
  3193   3193   int
  3194   3194   TclWinFileOwned(
  3195   3195       Tcl_Obj *pathPtr)		/* File whose ownership is to be checked */
  3196   3196   {
  3197         -    const TCHAR *native;
         3197  +    const WCHAR *native;
  3198   3198       PSID ownerSid = NULL;
  3199   3199       PSECURITY_DESCRIPTOR secd = NULL;
  3200   3200       HANDLE token;
  3201   3201       LPBYTE buf = NULL;
  3202   3202       DWORD bufsz;
  3203   3203       int owned = 0;
  3204   3204   

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       unsigned int *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  +    int 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 = TclGetString(pathPtr);
   227         -    *lengthPtr = pathPtr->length;
   228         -    *valuePtr = ckalloc(*lengthPtr + 1);
   229         -    memcpy(*valuePtr, bytes, *lengthPtr + 1);
          227  +    bytes = TclGetStringFromObj(pathPtr, &length);
          228  +    *lengthPtr = length++;
          229  +    *valuePtr = ckalloc(length);
          230  +    memcpy(*valuePtr, bytes, length);
   230    231       Tcl_DecrRefCount(pathPtr);
   231    232   }
   232    233   
   233    234   /*
   234    235    *---------------------------------------------------------------------------
   235    236    *
   236    237    * AppendEnvironment --
................................................................................
   464    465   TclpGetUserName(
   465    466       Tcl_DString *bufferPtr)	/* Uninitialized or free DString filled with
   466    467   				 * the name of user. */
   467    468   {
   468    469       Tcl_DStringInit(bufferPtr);
   469    470   
   470    471       if (TclGetEnv("USERNAME", bufferPtr) == NULL) {
   471         -	TCHAR szUserName[UNLEN+1];
          472  +	WCHAR szUserName[UNLEN+1];
   472    473   	DWORD cchUserNameLen = UNLEN;
   473    474   
   474    475   	if (!GetUserName(szUserName, &cchUserNameLen)) {
   475    476   	    return NULL;
   476    477   	}
   477    478   	cchUserNameLen--;
   478         -	cchUserNameLen *= sizeof(TCHAR);
          479  +	cchUserNameLen *= sizeof(WCHAR);
   479    480   	Tcl_WinTCharToUtf(szUserName, cchUserNameLen, bufferPtr);
   480    481       }
   481    482       return Tcl_DStringValue(bufferPtr);
   482    483   }
   483    484   
   484    485   /*
   485    486    *---------------------------------------------------------------------------
................................................................................
   512    513       static int osInfoInitialized = 0;
   513    514       Tcl_DString ds;
   514    515   
   515    516       Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL,
   516    517   	    TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY);
   517    518   
   518    519       if (!osInfoInitialized) {
   519         -	HMODULE handle = GetModuleHandle(TEXT("NTDLL"));
          520  +	HMODULE handle = GetModuleHandle(L"NTDLL");
   520    521   	int(__stdcall *getversion)(void *) =
   521    522   		(int(__stdcall *)(void *)) GetProcAddress(handle, "RtlGetVersion");
   522    523   	osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
   523    524   	if (!getversion || getversion(&osInfo)) {
   524    525   	    GetVersionExW(&osInfo);
   525    526   	}
   526    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       int length, counter, counter2;
  3109   3109       Tcl_DString buf;
  3110   3110   
  3111   3111       if (!resultingNameObj) {
................................................................................
  3113   3113       }
  3114   3114   
  3115   3115       namePtr = (char *) name;
  3116   3116       length = GetTempPath(MAX_PATH, name);
  3117   3117       if (length == 0) {
  3118   3118   	goto gotError;
  3119   3119       }
  3120         -    namePtr += length * sizeof(TCHAR);
         3120  +    namePtr += length * sizeof(WCHAR);
  3121   3121       if (basenameObj) {
  3122         -	const char *string = Tcl_GetString(basenameObj);
         3122  +	const char *string = TclGetStringFromObj(basenameObj, &length);
  3123   3123   
  3124         -	Tcl_WinUtfToTChar(string, basenameObj->length, &buf);
         3124  +	Tcl_WinUtfToTChar(string, length, &buf);
  3125   3125   	memcpy(namePtr, Tcl_DStringValue(&buf), Tcl_DStringLength(&buf));
  3126   3126   	namePtr += Tcl_DStringLength(&buf);
  3127   3127   	Tcl_DStringFree(&buf);
  3128   3128       } else {
  3129         -	const TCHAR *baseStr = TEXT("TCL");
  3130         -	int length = 3 * sizeof(TCHAR);
         3129  +	const WCHAR *baseStr = L"TCL";
         3130  +	length = 3 * sizeof(WCHAR);
  3131   3131   
  3132   3132   	memcpy(namePtr, baseStr, length);
  3133   3133   	namePtr += length;
  3134   3134       }
  3135   3135       counter = TclpGetClicks() % 65533;
  3136   3136       counter2 = 1024;			/* Only try this many times! Prevents
  3137   3137   					 * 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   1724   	    ckfree(argv);
  1725   1725   	    return TCL_ERROR;
  1726   1726   	}
  1727   1727   
  1728   1728   	/*
................................................................................
  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   1755   	ckfree(argv);
  1756   1756   
  1757   1757   	if (!SetCommState(infoPtr->handle, &dcb)) {
................................................................................
  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       unsigned int *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   	 */