Tcl Source Code

Check-in [d8764f73dd]
Login

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

Overview
Comment:Some Unicode encoding fixes, only having effect if TCL_UTF_MAX > 4. Backported from androwish
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d8764f73ddba27f0b5f7ce270d601ef1ace3e4fd
User & Date: jan.nijtmans 2015-08-31 10:18:31
Context
2020-04-20
06:45
Backport the encoding fix for source-7.2 in TCL_UTF_MAX=6 build. check-in: 024b7f7612 user: dgp tags: bug-c574e50a3b
2015-09-01
15:15
Whitespace reduction in Tcl scripts. No functional change. check-in: 401a39ba9a user: jan.nijtmans tags: trunk
2015-08-31
10:41
Merge trunk. Add Gustaf's latest fix for unit-tests. check-in: 3458e0ec21 user: jan.nijtmans tags: bug-5d170b5ca5
10:27
merge trunk check-in: bdab384a47 user: jan.nijtmans tags: tip-389-impl
10:22
Merge trunk, but remove experimental tip-389-impl merge. check-in: 6d59f33bbb user: jan.nijtmans tags: androwish
10:18
Some Unicode encoding fixes, only having effect if TCL_UTF_MAX > 4. Backported from androwish check-in: d8764f73dd user: jan.nijtmans tags: trunk
2015-08-30
20:21
[7703ff1082] Improved wording. check-in: 7e791e7784 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclDisassemble.c.

790
791
792
793
794
795
796

797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
PrintSourceToObj(
    Tcl_Obj *appendObj,		/* The object to print the source to. */
    const char *stringPtr,	/* The string to print. */
    int maxChars)		/* Maximum number of chars to print. */
{
    register const char *p;
    register int i = 0, len;


    if (stringPtr == NULL) {
	Tcl_AppendToObj(appendObj, "\"\"", -1);
	return;
    }

    Tcl_AppendToObj(appendObj, "\"", -1);
    p = stringPtr;
    for (;  (*p != '\0') && (i < maxChars);  p+=len) {
	Tcl_UniChar ch;

	len = TclUtfToUniChar(p, &ch);
	switch (ch) {
	case '"':
	    Tcl_AppendToObj(appendObj, "\\\"", -1);
	    i += 2;
	    continue;







>









<







790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806

807
808
809
810
811
812
813
PrintSourceToObj(
    Tcl_Obj *appendObj,		/* The object to print the source to. */
    const char *stringPtr,	/* The string to print. */
    int maxChars)		/* Maximum number of chars to print. */
{
    register const char *p;
    register int i = 0, len;
    Tcl_UniChar ch = 0;

    if (stringPtr == NULL) {
	Tcl_AppendToObj(appendObj, "\"\"", -1);
	return;
    }

    Tcl_AppendToObj(appendObj, "\"", -1);
    p = stringPtr;
    for (;  (*p != '\0') && (i < maxChars);  p+=len) {


	len = TclUtfToUniChar(p, &ch);
	switch (ch) {
	case '"':
	    Tcl_AppendToObj(appendObj, "\\\"", -1);
	    i += 2;
	    continue;
828
829
830
831
832
833
834






835
836
837
838
839
840
841
	    i += 2;
	    continue;
	case '\v':
	    Tcl_AppendToObj(appendObj, "\\v", -1);
	    i += 2;
	    continue;
	default:






	    if (ch < 0x20 || ch >= 0x7f) {
		Tcl_AppendPrintfToObj(appendObj, "\\u%04x", ch);
		i += 6;
	    } else {
		Tcl_AppendPrintfToObj(appendObj, "%c", ch);
		i++;
	    }







>
>
>
>
>
>







828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
	    i += 2;
	    continue;
	case '\v':
	    Tcl_AppendToObj(appendObj, "\\v", -1);
	    i += 2;
	    continue;
	default:
#if TCL_UTF_MAX > 4
	    if ((int) ch > 0xffff) {
		Tcl_AppendPrintfToObj(appendObj, "\\U%08x", (int) ch);
		i += 10;
	    } else
#endif
	    if (ch < 0x20 || ch >= 0x7f) {
		Tcl_AppendPrintfToObj(appendObj, "\\u%04x", ch);
		i += 6;
	    } else {
		Tcl_AppendPrintfToObj(appendObj, "%c", ch);
		i++;
	    }

Changes to generic/tclEncoding.c.

2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537






2538
2539







2540
2541
2542

2543
2544
2545
2546
2547
2548
2549

	    result = TCL_CONVERT_MULTIBYTE;
	    break;
	}
	if (dst > dstEnd) {
	    result = TCL_CONVERT_NOSPACE;
	    break;
        }
	src += TclUtfToUniChar(src, &ch);

	/*
	 * Need to handle this in a way that won't cause misalignment by
	 * casting dst to a Tcl_UniChar. [Bug 1122671]
	 * XXX: This hard-codes the assumed size of Tcl_UniChar as 2.
	 */

#ifdef WORDS_BIGENDIAN






	*dst++ = (ch >> 8);
	*dst++ = (ch & 0xFF);







#else
	*dst++ = (ch & 0xFF);
	*dst++ = (ch >> 8);

#endif
    }
    *srcReadPtr = src - srcStart;
    *dstWrotePtr = dst - dstStart;
    *dstCharsPtr = numChars;
    return result;
}







|





<



>
>
>
>
>
>


>
>
>
>
>
>
>



>







2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533

2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562

	    result = TCL_CONVERT_MULTIBYTE;
	    break;
	}
	if (dst > dstEnd) {
	    result = TCL_CONVERT_NOSPACE;
	    break;
	}
	src += TclUtfToUniChar(src, &ch);

	/*
	 * Need to handle this in a way that won't cause misalignment by
	 * casting dst to a Tcl_UniChar. [Bug 1122671]

	 */

#ifdef WORDS_BIGENDIAN
#if TCL_UTF_MAX > 4
	*dst++ = (ch >> 24);
	*dst++ = ((ch >> 16) & 0xFF);
	*dst++ = ((ch >> 8) & 0xFF);
	*dst++ = (ch & 0xFF);
#else
	*dst++ = (ch >> 8);
	*dst++ = (ch & 0xFF);
#endif
#else
#if TCL_UTF_MAX > 4
	*dst++ = (ch & 0xFF);
	*dst++ = ((ch >> 8) & 0xFF);
	*dst++ = ((ch >> 16) & 0xFF);
	*dst++ = (ch >> 24);
#else
	*dst++ = (ch & 0xFF);
	*dst++ = (ch >> 8);
#endif
#endif
    }
    *srcReadPtr = src - srcStart;
    *dstWrotePtr = dst - dstStart;
    *dstCharsPtr = numChars;
    return result;
}