diff options
| -rw-r--r-- | .travis.yml | 13 | ||||
| -rw-r--r-- | generic/tclEncoding.c | 16 | ||||
| -rw-r--r-- | generic/tclInt.h | 4 | ||||
| -rw-r--r-- | tests/chanio.test | 3 | ||||
| -rw-r--r-- | tests/encoding.test | 5 | ||||
| -rw-r--r-- | tests/io.test | 4 | ||||
| -rw-r--r-- | tests/source.test | 2 |
7 files changed, 18 insertions, 29 deletions
diff --git a/.travis.yml b/.travis.yml index 63c1645..b3ac5f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,19 +26,6 @@ matrix: env: - BUILD_DIR=unix - CFGOPT=CFLAGS=-DTCL_UTF_MAX=4 - script: - - make all tcltest - - make test TESTFLAGS="-file utf.test" - - name: "Linux/GCC/Shared: UTF_MAX=6" - os: linux - dist: bionic - compiler: gcc - env: - - BUILD_DIR=unix - - CFGOPT=CFLAGS=-DTCL_UTF_MAX=6 - script: - - make all tcltest - - make test TESTFLAGS="-file utf.test" - name: "Linux/GCC/Static" os: linux dist: bionic diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 6c16827..d948189 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -2359,13 +2359,12 @@ UnicodeToUtfProc( const char *srcStart, *srcEnd; char *dstEnd, *dstStart; int result, numChars; - Tcl_UniChar ch; + unsigned short ch; result = TCL_OK; - if ((srcLen % sizeof(Tcl_UniChar)) != 0) { + if ((srcLen & 1) != 0) { result = TCL_CONVERT_MULTIBYTE; - srcLen /= sizeof(Tcl_UniChar); - srcLen *= sizeof(Tcl_UniChar); + srcLen--; } srcStart = src; @@ -2383,13 +2382,13 @@ UnicodeToUtfProc( * Special case for 1-byte utf chars for speed. Make sure we * work with Tcl_UniChar-size data. */ - ch = *(Tcl_UniChar *)src; + ch = *(unsigned short *)src; if (ch && ch < 0x80) { *dst++ = (ch & 0xFF); } else { dst += Tcl_UniCharToUtf(ch, dst); } - src += sizeof(Tcl_UniChar); + src += sizeof(unsigned short); } *srcReadPtr = src - srcStart; @@ -2477,6 +2476,11 @@ UtfToUnicodeProc( * by casting dst to a Tcl_UniChar. [Bug 1122671] * XXX: This hard-codes the assumed size of Tcl_UniChar as 2. */ +#if TCL_UTF_MAX > 3 + if (ch & ~0xFFFF) { + ch = 0xFFFD; + } else +#endif #ifdef WORDS_BIGENDIAN *dst++ = (ch >> 8); *dst++ = (ch & 0xFF); diff --git a/generic/tclInt.h b/generic/tclInt.h index 3fa14e7..23a398f 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -102,6 +102,10 @@ typedef int ptrdiff_t; #define NO_WIDE_TYPE #endif +#if (TCL_UTF_MAX != 3) && (TCL_UTF_MAX != 4) +# error "Tcl 8.5 can only be built with TCL_UTF_MAX=3 or TCL_UTF_MAX=4" +#endif + /* * Macros used to cast between pointers and integers (e.g. when storing an int * in ClientData), on 64-bit architectures they avoid gcc warning about "cast diff --git a/tests/chanio.test b/tests/chanio.test index db4544c..5fae431 100644 --- a/tests/chanio.test +++ b/tests/chanio.test @@ -29,7 +29,6 @@ namespace eval ::tcl::test::io { variable msg variable expected - testConstraint ucs2 [expr {[format %c 0x010000] eq "\uFFFD"}] testConstraint testchannel [llength [info commands testchannel]] testConstraint exec [llength [info commands exec]] testConstraint openpipe 1 @@ -876,7 +875,7 @@ test chan-io-6.44 {Tcl_GetsObj: input saw cr, not followed by cr} {stdio testcha chan close $f set x } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"] -test chan-io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent ucs2} { +test chan-io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent} { # Tcl_ExternalToUtf() set f [open "|[list [interpreter] $path(cat)]" w+] diff --git a/tests/encoding.test b/tests/encoding.test index af325c1..8722a93 100644 --- a/tests/encoding.test +++ b/tests/encoding.test @@ -32,9 +32,6 @@ proc runtests {} { testConstraint testencoding [llength [info commands testencoding]] testConstraint exec [llength [info commands exec]] -testConstraint ucs2 [expr {[format %c 0x010000] eq "\uFFFD"}] - - # TclInitEncodingSubsystem is tested by the rest of this file # TclFinalizeEncodingSubsystem is not currently tested @@ -319,7 +316,7 @@ test encoding-15.3 {UtfToUtfProc null character input} { list [string bytelength $x] [string bytelength $y] $z } {1 2 c080} -test encoding-16.1 {UnicodeToUtfProc} ucs2 { +test encoding-16.1 {UnicodeToUtfProc} { set val [encoding convertfrom unicode NN] list $val [format %x [scan $val %c]] } "\u4e4e 4e4e" diff --git a/tests/io.test b/tests/io.test index 06be982..04fa1d2 100644 --- a/tests/io.test +++ b/tests/io.test @@ -29,8 +29,6 @@ namespace eval ::tcl::test::io { variable msg variable expected -testConstraint ucs2 [expr {[format %c 0x010000] eq "\uFFFD"}] - testConstraint testchannel [llength [info commands testchannel]] testConstraint exec [llength [info commands exec]] testConstraint openpipe 1 @@ -912,7 +910,7 @@ test io-6.44 {Tcl_GetsObj: input saw cr, not followed by cr} {stdio testchannel close $f set x } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"] -test io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent ucs2} { +test io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent} { # Tcl_ExternalToUtf() set f [open "|[list [interpreter] $path(cat)]" w+] diff --git a/tests/source.test b/tests/source.test index 877921e..1df5ac4 100644 --- a/tests/source.test +++ b/tests/source.test @@ -234,7 +234,7 @@ test source-7.1 {source -encoding test} -setup { } -cleanup { removeFile source.file } -result correct -test source-7.2 {source -encoding test} -constraints ucs2 -setup { +test source-7.2 {source -encoding test} -setup { # This tests for bad interactions between [source -encoding] # and use of the Control-Z character (\u001A) as a cross-platform # EOF character by [source]. Here we write out and the [source] a |
