Tcl Source Code

Check-in [4032e7fe99]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

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

Overview
Comment:Merge 8.7. Fix 2 test-cases which were failing for TCL_UTF_MAX=6
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | utf-max-6
Files: files | file ages | folders
SHA3-256:4032e7fe99cd747ff025baeb1ce12b3c5e4aa76cf7565ae5bcf83185ce7be21b
User & Date: jan.nijtmans 2019-03-14 20:59:28
Context
2019-03-16
21:10
Merge 8.7 Move up some stub entries related to Tcl_UniChar Use TCL_UTF_MAX=4 for full Unicode in ste... check-in: 81502a66ed user: jan.nijtmans tags: utf-max-6
2019-03-14
20:59
Merge 8.7. Fix 2 test-cases which were failing for TCL_UTF_MAX=6 check-in: 4032e7fe99 user: jan.nijtmans tags: utf-max-6
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-12
20:39
Even better support for -DTCL_UTF_MAX=6. Ongoing improvements (TIP being planned) check-in: fdcb2a7323 user: jan.nijtmans tags: utf-max-6
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tclEncoding.c.

  2668   2668   				 * stored in the output buffer as a result of
  2669   2669   				 * the conversion. */
  2670   2670       int *dstCharsPtr)		/* Filled with the number of characters that
  2671   2671   				 * correspond to the bytes stored in the
  2672   2672   				 * output buffer. */
  2673   2673   {
  2674   2674       const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
  2675         -    int result, numChars, len;
         2675  +    int result, numChars;
         2676  +#if TCL_UTF_MAX <= 4
         2677  +    int len;
         2678  +#endif
  2676   2679       Tcl_UniChar ch = 0;
  2677   2680   
  2678   2681       srcStart = src;
  2679   2682       srcEnd = src + srcLen;
  2680   2683       srcClose = srcEnd;
  2681   2684       if ((flags & TCL_ENCODING_END) == 0) {
  2682   2685   	srcClose -= TCL_UTF_MAX;
................................................................................
  2696   2699   	    result = TCL_CONVERT_MULTIBYTE;
  2697   2700   	    break;
  2698   2701   	}
  2699   2702   	if (dst > dstEnd) {
  2700   2703   	    result = TCL_CONVERT_NOSPACE;
  2701   2704   	    break;
  2702   2705   	}
         2706  +#if TCL_UTF_MAX <= 4
  2703   2707   	src += (len = TclUtfToUniChar(src, &ch));
  2704   2708   	if ((ch >= 0xD800) && (len < 3)) {
  2705   2709   	    src += TclUtfToUniChar(src, &ch);
  2706   2710   	    ch = 0xFFFD;
  2707   2711   	}
         2712  +#else
         2713  +	src += TclUtfToUniChar(src, &ch);
         2714  +	if (ch > 0xFFFF) {
         2715  +	    ch = 0xFFFD;
         2716  +	}
         2717  +#endif
  2708   2718   
  2709   2719   	/*
  2710   2720   	 * Need to handle this in a way that won't cause misalignment by
  2711   2721   	 * casting dst to a Tcl_UniChar. [Bug 1122671]
  2712   2722   	 */
  2713   2723   
  2714   2724   #ifdef WORDS_BIGENDIAN

Changes to generic/tclInt.h.

  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   3244   #if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
  3245         -MODULE_SCOPE int TclUtfToWChar(const char *src, WCHAR *chPtr);
         3245  +MODULE_SCOPE int TclUtfToUtf16(const char *src, unsigned short *chPtr);
  3246   3246   MODULE_SCOPE char *	Tcl_Utf16ToUtfDString(const unsigned short *uniStr,
  3247   3247   			    int uniLength, Tcl_DString *dsPtr);
  3248   3248   MODULE_SCOPE unsigned short * Tcl_UtfToUtf16DString(const char *src,
  3249   3249   			    int length, Tcl_DString *dsPtr);
  3250   3250   #else
  3251         -#   define TclUtfToWChar TclUtfToUniChar
         3251  +#   define TclUtfToUtf16 TclUtfToUniChar
  3252   3252   #   define Tcl_Utf16ToUtfDString Tcl_UniCharToUtfDString
  3253   3253   #   define Tcl_UtfToUtf16DString Tcl_UtfToUniCharDString
  3254   3254   #endif
  3255   3255   MODULE_SCOPE int	TclUtfCmp(const char *cs, const char *ct);
  3256   3256   MODULE_SCOPE int	TclUtfCasecmp(const char *cs, const char *ct);
  3257   3257   MODULE_SCOPE int	TclUtfCount(int ch);
  3258   3258   MODULE_SCOPE Tcl_Obj *	TclpNativeToNormalized(ClientData clientData);

Changes to generic/tclStubInit.c.

   276    276   	return NULL;
   277    277       }
   278    278       if (len < 0) {
   279    279   	len = wcslen((wchar_t *)string);
   280    280       } else {
   281    281   	len /= 2;
   282    282       }
   283         -    return Tcl_Utf16ToUtfDString((const WCHAR *)string, len, dsPtr);
          283  +    return Tcl_Utf16ToUtfDString((const unsigned short *)string, len, dsPtr);
   284    284   }
   285    285   
   286    286   #if defined(TCL_WIDE_INT_IS_LONG)
   287    287   /* On Cygwin64, long is 64-bit while on Win64 long is 32-bit. Therefore
   288    288    * we have to make sure that all stub entries on Cygwin64 follow the Win64
   289    289    * signature. Tcl 9 must find a better solution, but that cannot be done
   290    290    * without introducing a binary incompatibility.
................................................................................
   425    425   #   define TclpGmtime 0
   426    426   #   define TclpLocaltime_unix 0
   427    427   #   define TclpGmtime_unix 0
   428    428   #   define Tcl_SetExitProc 0
   429    429   #   define Tcl_SetPanicProc 0
   430    430   #   define Tcl_FindExecutable 0
   431    431   #   define TclOldFreeObj 0
          432  +#   define TclBN_reverse 0
          433  +#   define TclBN_fast_s_mp_mul_digs 0
          434  +#   define TclBN_fast_s_mp_sqr 0
          435  +#   define TclBN_mp_karatsuba_mul 0
          436  +#   define TclBN_mp_karatsuba_sqr 0
          437  +#   define TclBN_mp_toom_mul 0
          438  +#   define TclBN_mp_toom_sqr 0
          439  +#   define TclBN_s_mp_add 0
          440  +#   define TclBN_s_mp_mul_digs 0
          441  +#   define TclBN_s_mp_sqr 0
          442  +#   define TclBN_s_mp_sub 0
   432    443   #else /* TCL_NO_DEPRECATED */
   433    444   #   define Tcl_SeekOld seekOld
   434    445   #   define Tcl_TellOld tellOld
   435    446   #   define TclBackgroundException Tcl_BackgroundException
   436    447   #   define TclSetStartupScript Tcl_SetStartupScript
   437    448   #   define TclGetStartupScript Tcl_GetStartupScript
   438    449   #   define TclCreateNamespace Tcl_CreateNamespace

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)

Changes to generic/tclTomMathDecls.h.

   269    269   EXTERN int		TclBN_mp_unsigned_bin_size(const mp_int *a);
   270    270   /* 48 */
   271    271   EXTERN int		TclBN_mp_xor(const mp_int *a, const mp_int *b,
   272    272   				mp_int *c);
   273    273   /* 49 */
   274    274   EXTERN void		TclBN_mp_zero(mp_int *a);
   275    275   /* 50 */
   276         -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);
   277    278   /* 51 */
   278         -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,
   279    281   				const mp_int *b, mp_int *c, int digs);
   280    282   /* 52 */
   281         -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);
   282    285   /* 53 */
   283         -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,
   284    288   				const mp_int *b, mp_int *c);
   285    289   /* 54 */
   286         -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);
   287    292   /* 55 */
   288         -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,
   289    295   				mp_int *c);
   290    296   /* 56 */
   291         -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);
   292    299   /* 57 */
   293         -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,
   294    302   				mp_int *c);
   295    303   /* 58 */
   296         -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,
   297    306   				mp_int *c, int digs);
   298    307   /* 59 */
   299         -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);
   300    310   /* 60 */
   301         -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,
   302    313   				mp_int *c);
   303    314   /* 61 */
   304    315   EXTERN int		TclBN_mp_init_set_int(mp_int *a, unsigned long i);
   305    316   /* 62 */
   306    317   EXTERN int		TclBN_mp_set_int(mp_int *a, unsigned long i);
   307    318   /* 63 */
   308    319   EXTERN int		TclBN_mp_cnt_lsb(const mp_int *a);
................................................................................
   394    405       int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
   395    406       int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
   396    407       int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
   397    408       int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
   398    409       int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
   399    410       int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
   400    411       void (*tclBN_mp_zero) (mp_int *a); /* 49 */
   401         -    void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
   402         -    int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
   403         -    int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
   404         -    int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
   405         -    int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
   406         -    int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
   407         -    int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
   408         -    int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
   409         -    int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
   410         -    int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
   411         -    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 */
   412    423       int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
   413    424       int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
   414    425       int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
   415    426       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
   416    427       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
   417    428       TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
   418    429       int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */

Changes to generic/tclUtf.c.

   265    265   
   266    266       return string;
   267    267   }
   268    268   
   269    269   #if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
   270    270   char *
   271    271   Tcl_Utf16ToUtfDString(
   272         -    const unsigned short *uniStr,	/* WCHAR string to convert to UTF-8. */
   273         -    int uniLength,		/* Length of WCHAR string in Tcl_UniChars
   274         -				 * (must be >= 0). */
          272  +    const unsigned short *uniStr,	/* Utf-16 string to convert to UTF-8. */
          273  +    int uniLength,		/* Length of Utf-16 string (must be >= 0). */
   275    274       Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
   276    275   				 * to this previously initialized DString. */
   277    276   {
   278    277       const unsigned short *w, *wEnd;
   279    278       char *p, *string;
   280    279       int oldLength, len = 1;
   281    280   
................................................................................
   442    441   		/* produce high surrogate, advance source pointer */
   443    442   		*chPtr = 0xD800 + high;
   444    443   		return 1;
   445    444   	    }
   446    445   #else
   447    446   	    *chPtr = (((byte & 0x07) << 18) | ((src[1] & 0x3F) << 12)
   448    447   		    | ((src[2] & 0x3F) << 6) | (src[3] & 0x3F));
   449         -	    if ((*chPtr - 0x10000) <= 0xFFFFF) {
          448  +	    if (((unsigned)(*chPtr) - 0x10000) <= 0xFFFFF) {
   450    449   		return 4;
   451    450   	    }
   452    451   #endif
   453    452   	}
   454    453   
   455    454   	/*
   456    455   	 * A four-byte-character lead-byte not followed by two trail-bytes
................................................................................
   460    459   
   461    460       *chPtr = byte;
   462    461       return 1;
   463    462   }
   464    463   
   465    464   #if (TCL_UTF_MAX > 4) && (defined(__CYGWIN__) || defined(_WIN32))
   466    465   int
   467         -TclUtfToWChar(
          466  +TclUtfToUtf16(
   468    467       const char *src,	/* The UTF-8 string. */
   469         -    WCHAR *chPtr)/* Filled with the WCHAR represented by
          468  +    unsigned short *chPtr)/* Filled with the Utf-16 representation of
   470    469   				 * the UTF-8 string. */
   471    470   {
   472         -    WCHAR byte;
          471  +    unsigned short byte;
   473    472   
   474    473       /*
   475    474        * Unroll 1 to 4 byte UTF-8 sequences.
   476    475        */
   477    476   
   478    477       byte = *((unsigned char *) src);
   479    478       if (byte < 0xC0) {
................................................................................
   538    537   	 */
   539    538       }
   540    539       else if (byte < 0xF8) {
   541    540   	if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80) && ((src[3] & 0xC0) == 0x80)) {
   542    541   	    /*
   543    542   	     * Four-byte-character lead byte followed by three trail bytes.
   544    543   	     */
   545         -	    WCHAR high = (((byte & 0x07) << 8) | ((src[1] & 0x3F) << 2)
          544  +	    unsigned short high = (((byte & 0x07) << 8) | ((src[1] & 0x3F) << 2)
   546    545   		    | ((src[2] & 0x3F) >> 4)) - 0x40;
   547    546   	    if (high >= 0x400) {
   548    547   		/* out of range, < 0x10000 or > 0x10ffff */
   549    548   	    } else {
   550    549   		/* produce high surrogate, advance source pointer */
   551    550   		*chPtr = 0xD800 + high;
   552    551   		return 1;
................................................................................
   641    640       const char *src,		/* UTF-8 string to convert to Unicode. */
   642    641       int length,			/* Length of UTF-8 string in bytes, or -1 for
   643    642   				 * strlen(). */
   644    643       Tcl_DString *dsPtr)		/* Unicode representation of string is
   645    644   				 * appended to this previously initialized
   646    645   				 * DString. */
   647    646   {
   648         -    WCHAR ch = 0, *w, *wString;
          647  +    unsigned short ch = 0, *w, *wString;
   649    648       const char *p, *end;
   650    649       int oldLength;
   651    650   
   652    651       if (length < 0) {
   653    652   	length = strlen(src);
   654    653       }
   655    654   
................................................................................
   657    656        * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
   658    657        * bytes.
   659    658        */
   660    659   
   661    660       oldLength = Tcl_DStringLength(dsPtr);
   662    661   
   663    662       Tcl_DStringSetLength(dsPtr,
   664         -	    oldLength + (int) ((length + 1) * sizeof(WCHAR)));
   665         -    wString = (WCHAR *) (Tcl_DStringValue(dsPtr) + oldLength);
          663  +	    oldLength + (int) ((length + 1) * sizeof(unsigned short)));
          664  +    wString = (unsigned short *) (Tcl_DStringValue(dsPtr) + oldLength);
   666    665   
   667    666       w = wString;
   668    667       p = src;
   669    668       end = src + length - 4;
   670    669       while (p < end) {
   671         -	p += TclUtfToWChar(p, &ch);
          670  +	p += TclUtfToUtf16(p, &ch);
   672    671   	*w++ = ch;
   673    672       }
   674    673       end += 4;
   675    674       while (p < end) {
   676    675   	if (Tcl_UtfCharComplete(p, end-p)) {
   677         -	    p += TclUtfToWChar(p, &ch);
          676  +	    p += TclUtfToUtf16(p, &ch);
   678    677   	} else if (((UCHAR(*p)-0x80)) < 0x20) {
   679    678   	    ch = cp1252[UCHAR(*p++)-0x80];
   680    679   	} else {
   681    680   	    ch = UCHAR(*p++);
   682    681   	}
   683    682   	*w++ = ch;
   684    683       }