Tcl Source Code

Check-in [f019af39bd]
Login

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

Overview
Comment:[Bug 3466099] BOM in Unicode
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-3466099
Files: files | file ages | folders
SHA1: f019af39bdde58b4eb43d74dd985debfab22316a
User & Date: jan.nijtmans 2012-02-19 15:21:27
Context
2012-02-20
11:55
Make test clearer to future maintainers. Closed-Leaf check-in: a1ab7b1a0c user: dkf tags: bug-3466099
2012-02-19
15:21
[Bug 3466099] BOM in Unicode check-in: f019af39bd user: jan.nijtmans tags: bug-3466099
2012-02-09
14:57
3484402 Correct Off-By-One error appending unicode. Thanks to Poor Yorick. Also corrected test for w... check-in: f57b5ba48d user: dgp tags: core-8-4-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.







1
2
3
4
5
6
7






2012-02-09  Don Porter  <[email protected]>

	* generic/tclStringObj.c:	[Bug 3484402] Correct Off-By-One
	error appending unicode. Thanks to Poor Yorick. Also corrected test
	for when growth is needed. 

2012-02-06  Don Porter  <[email protected]>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2012-02-??  Jan Nijtmans  <[email protected]>

	* generic/tclIOUtil.c:	[Bug bug-3466099] BOM in Unicode
	* generic/tclEncoding.c:
	* tests/source.test

2012-02-09  Don Porter  <[email protected]>

	* generic/tclStringObj.c:	[Bug 3484402] Correct Off-By-One
	error appending unicode. Thanks to Poor Yorick. Also corrected test
	for when growth is needed. 

2012-02-06  Don Porter  <[email protected]>

Changes to generic/tclEncoding.c.

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
 *
 *------------------------------------------------------------------------
 */

int
Tcl_SetSystemEncoding(interp, name)
    Tcl_Interp *interp;		/* Interp for error reporting, if not NULL. */
    CONST char *name;		/* The name of the desired encoding, or NULL
				 * to reset to default encoding. */
{
    Tcl_Encoding encoding;
    Encoding *encodingPtr;

    if (name == NULL) {
	Tcl_MutexLock(&encodingMutex);
	encoding = defaultEncoding;
	encodingPtr = (Encoding *) encoding;
	encodingPtr->refCount++;
	Tcl_MutexUnlock(&encodingMutex);
    } else {
	encoding = Tcl_GetEncoding(interp, name);







|





|







760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
 *
 *------------------------------------------------------------------------
 */

int
Tcl_SetSystemEncoding(interp, name)
    Tcl_Interp *interp;		/* Interp for error reporting, if not NULL. */
    CONST char *name;		/* The name of the desired encoding, or NULL/""
				 * to reset to default encoding. */
{
    Tcl_Encoding encoding;
    Encoding *encodingPtr;

    if (!name || !*name) {
	Tcl_MutexLock(&encodingMutex);
	encoding = defaultEncoding;
	encodingPtr = (Encoding *) encoding;
	encodingPtr->refCount++;
	Tcl_MutexUnlock(&encodingMutex);
    } else {
	encoding = Tcl_GetEncoding(interp, name);

Changes to generic/tclIOUtil.c.

1751
1752
1753
1754
1755
1756
1757

1758
1759
1760
1761







1762
1763
1764
1765
1766
1767
1768
1769
    }
    /*
     * The eofchar is \32 (^Z).  This is the usual on Windows, but we
     * effect this cross-platform to allow for scripted documents.
     * [Bug: 2040]
     */
    Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");

    if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) {
        Tcl_Close(interp, chan);
	Tcl_AppendResult(interp, "couldn't read file \"", 
		Tcl_GetString(pathPtr),







		"\": ", Tcl_PosixError(interp), (char *) NULL);
	goto end;
    }
    if (Tcl_Close(interp, chan) != TCL_OK) {
        goto end;
    }

    iPtr = (Interp *) interp;







>
|
|

|
>
>
>
>
>
>
>
|







1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
    }
    /*
     * The eofchar is \32 (^Z).  This is the usual on Windows, but we
     * effect this cross-platform to allow for scripted documents.
     * [Bug: 2040]
     */
    Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");
    /* Try to read utf-8 BOM, if available */
    if (Tcl_ReadChars(chan, objPtr, 1, 0) < 0) {
	Tcl_Close(interp, chan);
	Tcl_AppendResult(interp, "couldn't read file \"", 
		Tcl_GetString(pathPtr),	"\": ", Tcl_PosixError(interp), NULL);
	goto end;
    }
    string = Tcl_GetString(objPtr);
    if (Tcl_ReadChars(chan, objPtr, -1,
	    memcmp(string, "\xef\xbf\xbe", 3)) < 0) {
	Tcl_Close(interp, chan);
	Tcl_AppendResult(interp, "couldn't read file \"",
		Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), NULL);
	goto end;
    }
    if (Tcl_Close(interp, chan) != TCL_OK) {
        goto end;
    }

    iPtr = (Interp *) interp;

Changes to tests/source.test.

114
115
116
117
118
119
120















121
122
123
124
125
126
127
    removeFile _non_existent_
} -body {
    list [catch {source $sourcefile} msg] $msg $::errorCode
} -match listGlob -result [list 1 \
	{couldn't read file "*_non_existent_": no such file or directory} \
	{POSIX ENOENT {no such file or directory}}]

















test source-3.1 {return in middle of source file} -setup {
    set sourcefile [makeFile {
	set x new-x
	return allDone
	set y new-y
    } source.file]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    removeFile _non_existent_
} -body {
    list [catch {source $sourcefile} msg] $msg $::errorCode
} -match listGlob -result [list 1 \
	{couldn't read file "*_non_existent_": no such file or directory} \
	{POSIX ENOENT {no such file or directory}}]

test source-2.7 {utf-8 with BOM} -setup {
    set sourcefile [makeFile {} source.file]
    set saveencoding [encoding system]
    encoding system utf-8
    set out [open $sourcefile w]
    puts $out "\ufffeset y new-y"
    close $out
} -body {
   set y old-y
    source $sourcefile
    set y
} -cleanup {
    removeFile source.file
    encoding system $saveencoding
} -result {new-y}

test source-3.1 {return in middle of source file} -setup {
    set sourcefile [makeFile {
	set x new-x
	return allDone
	set y new-y
    } source.file]