Compare commits

...
Author SHA1 Message Date
jan.nijtmans 9a3567395e merge-mark 2023-05-09 16:15:30 +00:00
jan.nijtmans fc3837a30a merge-mark 2023-05-09 16:14:04 +00:00
jan.nijtmans dbddc6a2f8 Merge TIP #657 2023-05-09 15:43:50 +00:00
jan.nijtmans 6701945b81 Merge 9.0 2023-05-09 15:43:04 +00:00
jan.nijtmans b513d87d24 Merge tip-657 2023-05-05 06:21:43 +00:00
jan.nijtmans 91c305a5f3 Remove more ... to be split off in separate TIP's 2023-05-05 06:18:55 +00:00
jan.nijtmans f608dc525e Remove special "-failindex" handling. 2023-05-04 19:59:39 +00:00
jan.nijtmans c3609d23d9 merge tip-657 2023-05-04 19:56:13 +00:00
jan.nijtmans 83776b137b Tcl_InputEncodingError() -> TclInputEncodingError. It will be split off in a separate TIP 2023-05-04 19:53:44 +00:00
jan.nijtmans 2b094e49f6 Merge tip-657 2023-05-04 16:59:30 +00:00
jan.nijtmans 4ae09b6572 Merge 9.0 2023-05-04 13:27:36 +00:00
jan.nijtmans cb008d57c8 Some int -> Tcl_Size. Remove unnecessary knownBug constraint 2023-05-04 06:44:22 +00:00
jan.nijtmans 32ef665a1f Rebase to latest 9.0 2023-05-04 06:38:34 +00:00
jan.nijtmans e808862660 Merge 9.0 2023-05-03 09:20:21 +00:00
jan.nijtmans 2856f45d61 Merge tip-657 2023-04-23 22:21:40 +00:00
jan.nijtmans cdf2e470a4 Merge 9.0 2023-04-23 22:20:58 +00:00
jan.nijtmans e858a80613 Merge tip-657 2023-04-23 09:48:07 +00:00
jan.nijtmans fe77293e49 Merge 9.0 2023-04-23 09:46:54 +00:00
jan.nijtmans a8609aeb89 Merge tip-657 2023-04-21 21:45:22 +00:00
jan.nijtmans 05e1eca301 Merge 9.0 2023-04-21 21:31:25 +00:00
jan.nijtmans cf3686df07 Merge tip-657 2023-04-18 21:22:35 +00:00
jan.nijtmans 9e82399a14 Merge 9.0 2023-04-18 21:05:38 +00:00
jan.nijtmans 337ab3f387 Merge 9.0 2023-04-15 21:14:50 +00:00
jan.nijtmans c09ca7ee60 Merge tip-657 2023-04-14 07:04:12 +00:00
jan.nijtmans 4d44b91a10 Merge 9.0 2023-04-14 07:03:22 +00:00
jan.nijtmans c43d7064eb Merge 9.0 2023-04-12 22:41:14 +00:00
jan.nijtmans 6138f9c868 Merge tip-659 2023-04-05 15:57:28 +00:00
jan.nijtmans 3e8b4007cf Merge 9.0 2023-04-05 15:56:33 +00:00
jan.nijtmans 00d74a5b5d Merge tip-657 2023-04-01 15:26:10 +00:00
jan.nijtmans 93cc703cc9 Remove TCL_ENCODING_PROFILE_DEFAULT, since it isn't documented and is not used anywhere. 2023-04-01 15:09:11 +00:00
jan.nijtmans f923b422e9 Merge 9.0 2023-04-01 15:04:41 +00:00
jan.nijtmans 656d6d7b05 Merge tip-657 2023-04-01 10:31:53 +00:00
jan.nijtmans 2a8ae1943e Merge 9.0 2023-04-01 08:42:01 +00:00
jan.nijtmans 5102b0f3cf Rebase to tip-657 2023-03-31 22:07:31 +00:00
jan.nijtmans 4f5c603784 Rebase to 9.0 2023-03-31 22:05:31 +00:00
jan.nijtmans 0758324455 Merge 9.0 2023-03-30 22:27:40 +00:00
jan.nijtmans d960231479 Remove TCL_ENCODING_PROFILE_DEFAULT 2023-03-30 06:24:20 +00:00
jan.nijtmans 5cd0b1d22a Make "file tempfile" adhere default profile 2023-03-29 16:49:26 +00:00
jan.nijtmans 393fc22411 Rebase to tip-657 2023-03-28 15:55:44 +00:00
jan.nijtmans 812c3e3103 Rebase to 9.0 2023-03-28 15:54:21 +00:00
jan.nijtmans 594f1e7e76 Rebase to tip-657. Further implementation 2023-03-28 15:48:14 +00:00
jan.nijtmans aa00ed70ea Merge 9.0 2023-03-28 14:34:31 +00:00
jan.nijtmans 7973edde00 First shot at TIP #659 implementation. Not complete yet (many parts still missing!!!) 2023-03-23 17:51:42 +00:00
jan.nijtmans 2ffd05e703 documentation update 2023-03-23 17:31:37 +00:00
jan.nijtmans de5eea858b Merge 9.0 2023-03-23 16:15:51 +00:00
jan.nijtmans 76b980b1d8 Merge 9.0 2023-03-22 21:18:20 +00:00
jan.nijtmans 3eefce40b9 Merge 9.0 2023-03-22 20:13:46 +00:00
jan.nijtmans 2410f4ec9d Merge 9.0 2023-03-22 19:32:33 +00:00
jan.nijtmans 5761d7e651 Merge 9.0 2023-03-22 15:27:51 +00:00
jan.nijtmans ea9abbf7ea Merge 9.0 2023-03-22 08:34:54 +00:00
jan.nijtmans 34ecddb610 exchange profile <-> eofchar output in "fconfigure". Fix some testcases, which depend on profile 2023-03-21 17:47:33 +00:00
jan.nijtmans 9291cbb6cf Merge 9.0 2023-03-21 17:21:33 +00:00
jan.nijtmans 94dfe61832 Merge 9.0 2023-03-20 14:30:42 +00:00
jan.nijtmans 3cc7a1e953 Merge 9.0. Backout previous commit 2023-03-19 12:02:11 +00:00
jan.nijtmans 0625218c85 See if less "-profile replace" suffices 2023-03-18 13:36:10 +00:00
jan.nijtmans 219cbfee38 Merge 9.0 2023-03-18 09:10:24 +00:00
jan.nijtmans 59a954a7ae Merge 9.0 2023-03-18 08:57:48 +00:00
jan.nijtmans b6ccec9b3f Don't reset CHANNEL_ENCODING_ERROR here, otherwise Tcl_InputEncodingError() will give wrong result 2023-03-16 21:03:28 +00:00
jan.nijtmans 5e75946997 Merge tip-656-tcl9 2023-03-16 20:35:40 +00:00
jan.nijtmans 0494380d8a Merge tip-656-tcl9 2023-03-16 10:24:24 +00:00
jan.nijtmans 3ac0d72dd6 Allow -encoding to be shortened (again) 2023-03-16 08:22:35 +00:00
jan.nijtmans 4ea3b1ce77 merge-mark (this branch already did the -encodingprofile -> profile change) 2023-03-16 08:20:19 +00:00
jan.nijtmans ef949221f5 Merge tip-656-tcl9 2023-03-14 20:55:52 +00:00
jan.nijtmans d023df8623 Implement return options for read/gets 2023-03-14 20:24:27 +00:00
jan.nijtmans 362a0e8ba6 Adapt more test expectation (since the default is now -profile strict) 2023-03-13 17:24:22 +00:00
jan.nijtmans e36b69fb4d Merge tip-656-tcl9. Mark xx-bufferoverflow as knownBug 2023-03-13 17:05:14 +00:00
jan.nijtmans c43f6e9701 More utf-16 bugfixing 2023-03-12 13:45:51 +00:00
jan.nijtmans a71ab1a3ea Merge tip-656-tcl9 2023-03-12 12:11:02 +00:00
jan.nijtmans f5bd004df9 Make testcase io-53.5 independant on system encoding 2023-03-12 11:51:17 +00:00
jan.nijtmans 9e4ce6c3b9 Fix last (hopefully) bugs in utf-16/utf-32 encoders 2023-03-11 21:19:46 +00:00
jan.nijtmans 5e73d72846 Merge tip-656-tcl9 2023-03-10 16:02:27 +00:00
jan.nijtmans 6e644e2a60 Implement new function Tcl_InputEncodingError() 2023-03-10 15:55:51 +00:00
jan.nijtmans 2ff0d1c5c1 Bug-fix for Utf32ToUtfProc, in case TCL_UTF_MAX=3 2023-03-09 16:20:30 +00:00
jan.nijtmans 5669c89824 Oops 2023-03-08 22:04:09 +00:00
jan.nijtmans 8b4325141a Merge tip-657-tcl9. Further implementation of Tcl_GetObj() et al. 2023-03-08 21:49:11 +00:00
jan.nijtmans 716757e45f Merge tip-657-tcl9. Add "-profile tcl8" to http.tcl 2023-03-08 09:52:06 +00:00
jan.nijtmans 0eaea8713d encodingprofile -> profile, and fix more testcases 2023-03-07 23:11:17 +00:00
jan.nijtmans f562be24c3 Start implementing TIP #657. WIP 2023-03-07 21:01:32 +00:00
19 changed files with 105 additions and 129 deletions
+6 -4
View File
@@ -15,7 +15,7 @@ Tcl_CreateChannel, Tcl_GetChannelInstanceData, Tcl_GetChannelType, Tcl_GetChanne
\fB#include <tcl.h>\fR
.sp
Tcl_Channel
\fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, mask\fR)
\fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, flags\fR)
.sp
void *
\fBTcl_GetChannelInstanceData\fR(\fIchannel\fR)
@@ -130,9 +130,11 @@ the assigned channel name will be the name of the standard channel.
.AP void *instanceData in
Arbitrary one-word value to be associated with this channel. This
value is passed to procedures in \fItypePtr\fR when they are invoked.
.AP int mask in
.AP int flags in
OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate
whether a channel is readable and writable.
whether a channel is readable and writable. Can also be combined with
one of \fBTCL_ENCODING_PROFILE_STRICT\fR, \fBTCL_ENCODING_PROFILE_TCL8\fR,
or \fBTCL_ENCODING_PROFILE_REPLACE\fR.
.AP Tcl_Channel channel in
The channel to operate on.
.AP int direction in
@@ -200,7 +202,7 @@ structure to perform operations on the channel.
.PP
\fBTcl_CreateChannel\fR opens a new channel and associates the supplied
\fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in the
mode indicated by \fImask\fR.
mode indicated by \fIflags\fR.
For a discussion of channel drivers, their operations and the
\fBTcl_ChannelType\fR structure, see the section \fBTCL_CHANNELTYPE\fR, below.
.PP
+4 -4
View File
@@ -105,9 +105,9 @@ byte is converted and then to reset to an initial state. The
\fBTCL_PROFILE_*\fR bits defined in the \fBPROFILES\fR section below
control the encoding profile to be used for dealing with invalid data or
other errors in the encoding transform.
\fBTCL_ENCODING_STOPONERROR\fR is present for backward compatibility with
Tcl 8.6 and forces the encoding profile to \fBstrict\fR.
The flag \fBTCL_ENCODING_STOPONERROR\fR has no effect,
it only has meaning in Tcl 8.x.
.PP
Some flags bits may not be usable with some functions as noted in the
function descriptions below.
.AP Tcl_EncodingState *statePtr in/out
@@ -590,7 +590,7 @@ with at most one of \fBTCL_ENCODING_PROFILE_TCL8\fR,
\fBTCL_ENCODING_PROFILE_STRICT\fR or \fBTCL_ENCODING_PROFILE_REPLACE\fR.
These correspond to the \fBtcl8\fR, \fBstrict\fR and \fBreplace\fR profiles
respectively. If none are specified, a version-dependent default profile is used.
For Tcl 9.0, the default profile is \fBtcl8\fR.
For Tcl 9.0, the default profile is \fBstrict\fR.
.PP
For details about profiles, see the \fBPROFILES\fR section in
the documentation of the \fBencoding\fR command.
+5 -3
View File
@@ -21,7 +21,7 @@ Tcl_Channel
\fBTcl_OpenCommandChannel\fR(\fIinterp, argc, argv, flags\fR)
.sp
Tcl_Channel
\fBTcl_MakeFileChannel\fR(\fIhandle, readOrWrite\fR)
\fBTcl_MakeFileChannel\fR(\fIhandle, mask\fR)
.sp
Tcl_Channel
\fBTcl_GetChannel\fR(\fIinterp, channelName, modePtr\fR)
@@ -137,9 +137,11 @@ is set, then such redirections cause an error.
.AP void *handle in
Operating system specific handle for I/O to a file. For Unix this is a
file descriptor, for Windows it is a HANDLE.
.AP int readOrWrite in
.AP int mask in
OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate
what operations are valid on \fIhandle\fR.
what operations are valid on \fIhandle\fR. Can also be combined with
one of \fBTCL_ENCODING_PROFILE_STRICT\fR, \fBTCL_ENCODING_PROFILE_TCL8\fR,
or \fBTCL_ENCODING_PROFILE_REPLACE\fR.
.AP "const char" *channelName in
The name of the channel.
.AP int *modePtr out
+9 -7
View File
@@ -111,9 +111,15 @@ encoding.
The following profiles are currently implemented.
.VS "TCL8.7 TIP656"
.TP
\fBstrict\fR
.
The default profile, unless the environment variable \fBTCL_PROFILE_DEFAULT\fR
is set to either "tcl8" or "replace". The operation fails when invalid data for the encoding
are encountered.
.TP
\fBtcl8\fR
.
The default profile. Provides for behaviour identical to that of Tcl 8.6: When
Provides for behaviour identical to that of Tcl 8.6: When
decoding, for encodings \fBother than utf-8\fR, each invalid byte is interpreted
as the Unicode value given by that one byte. For example, the byte 0x80, which
is invalid in the ASCII encoding would be mapped to the Unicode value U+0080.
@@ -127,10 +133,6 @@ an additional special case, the sequence 0xC0 0x80 is mapped to U+0000.
When encoding, each character that cannot be represented in the encoding is
replaced by an encoding-dependent character, usually the question mark \fB?\fR.
.TP
\fBstrict\fR
.
The operation fails when invalid data for the encoding are encountered.
.TP
\fBreplace\fR
.
When decoding, invalid bytes are replaced by U+FFFD, the Unicode REPLACEMENT
@@ -180,7 +182,7 @@ unexpected byte sequence starting at index 1: '\ex80'
Example 3: Get partial data and the error location:
.PP
.CS
% codepoints [encoding convertfrom -profile strict -failindex idx ascii AB\ex80]
% codepoints [encoding convertfrom -failindex idx ascii AB\ex80]
U+000041 U+000042
% set idx
2
@@ -193,7 +195,7 @@ Example 4: Encode a character that is not representable in ISO8859-1:
A?
% encoding convertto -profile strict iso8859-1 A\eu0141
unexpected character at index 1: 'U+000141'
% encoding convertto -profile strict -failindex idx iso8859-1 A\eu0141
% encoding convertto -failindex idx iso8859-1 A\eu0141
A
% set idx
1
+2 -7
View File
@@ -1972,14 +1972,9 @@ typedef struct Tcl_EncodingType {
* changes, ensure ENCODING_PROFILE_* macros in tclInt.h are modified if
* necessary.
*/
#define TCL_ENCODING_PROFILE_STRICT TCL_ENCODING_STOPONERROR
#define TCL_ENCODING_PROFILE_TCL8 0x01000000
#define TCL_ENCODING_PROFILE_STRICT 0x02000000
#define TCL_ENCODING_PROFILE_REPLACE 0x03000000
#if TCL_MAJOR_VERSION < 9
#define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8
#else
#define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8
#endif
#define TCL_ENCODING_PROFILE_REPLACE 0x02000000
/*
* The following definitions are the error codes returned by the conversion
+20 -1
View File
@@ -883,7 +883,26 @@ Tcl_CreateInterp(void)
iPtr->resolverPtr = NULL;
iPtr->evalFlags = 0;
iPtr->scriptFile = NULL;
iPtr->flags = 0;
iPtr->flags = TCL_ENCODING_PROFILE_STRICT;
#ifdef _WIN32
wchar_t *defaultProfile = getenv("TCL_PROFILE_DEFAULT");
if (defaultProfile != NULL) {
if (!wcscmp(defaultProfile, L"tcl8")) {
iPtr->flags = TCL_ENCODING_PROFILE_TCL8;
} else if (!wcscmp(defaultProfile, L"replace")) {
iPtr->flags = TCL_ENCODING_PROFILE_REPLACE;
}
}
#else
char *defaultProfile = getenv("TCL_PROFILE_DEFAULT");
if (defaultProfile != NULL) {
if (!strcmp(defaultProfile, "tcl8")) {
iPtr->flags = TCL_ENCODING_PROFILE_TCL8;
} else if (!strcmp(defaultProfile, "replace")) {
iPtr->flags = TCL_ENCODING_PROFILE_REPLACE;
}
}
#endif
iPtr->tracePtr = NULL;
iPtr->tracesForbiddingInline = 0;
iPtr->activeCmdTracePtr = NULL;
+4 -1
View File
@@ -435,7 +435,7 @@ EncodingConvertParseOptions (
Tcl_Encoding encoding;
Tcl_Obj *dataObj;
Tcl_Obj *failVarObj;
int profile = TCL_ENCODING_PROFILE_TCL8;
int profile = -1;
/*
* Possible combinations:
@@ -494,6 +494,9 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */
dataObj = objv[objc - 1];
}
if (profile == -1) {
profile = ENCODING_PROFILE_GET(((Interp *)interp)->flags);
}
*encPtr = encoding;
*dataObjPtr = dataObj;
*profilePtr = profile;
+5 -72
View File
@@ -198,18 +198,11 @@ static struct TclEncodingProfiles {
{"strict", TCL_ENCODING_PROFILE_STRICT},
{"tcl8", TCL_ENCODING_PROFILE_TCL8},
};
#define PROFILE_TCL8(flags_) \
((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_TCL8) \
|| (ENCODING_PROFILE_GET(flags_) == 0 \
&& TCL_ENCODING_PROFILE_DEFAULT == TCL_ENCODING_PROFILE_TCL8))
#define PROFILE_STRICT(flags_) \
((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) \
|| (ENCODING_PROFILE_GET(flags_) == 0 \
&& TCL_ENCODING_PROFILE_DEFAULT == TCL_ENCODING_PROFILE_STRICT))
(ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT)
#define PROFILE_REPLACE(flags_) \
((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) \
|| (ENCODING_PROFILE_GET(flags_) == 0 \
&& TCL_ENCODING_PROFILE_DEFAULT == TCL_ENCODING_PROFILE_REPLACE))
(ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE)
#define UNICODE_REPLACE_CHAR ((Tcl_UniChar)0xFFFD)
#define SURROGATE(c_) (((c_) & ~0x7FF) == 0xD800)
@@ -1170,10 +1163,6 @@ Tcl_ExternalToUtfDString(
* Possible flags values:
* target encoding. It should be composed by OR-ing the following:
* - *At most one* of TCL_ENCODING_PROFILE{DEFAULT,TCL8,STRICT}
* - TCL_ENCODING_STOPONERROR: Backward compatibility. Sets the profile
* to TCL_ENCODING_PROFILE_STRICT overriding any specified profile flags
* Any other flag bits will cause an error to be returned (for future
* compatibility)
*
* Results:
* The return value is one of
@@ -1500,8 +1489,6 @@ Tcl_UtfToExternalDString(
* the source buffer are invalid or cannot be represented in the
* target encoding. It should be composed by OR-ing the following:
* - *At most one* of TCL_ENCODING_PROFILE{DEFAULT,TCL8,STRICT}
* - TCL_ENCODING_STOPONERROR: Backward compatibility. Sets the profile
* to TCL_ENCODING_PROFILE_STRICT overriding any specified profile flags
*
* Results:
* The return value is one of
@@ -2451,7 +2438,6 @@ BinaryProc(
if (dstLen < 0) {
dstLen = 0;
}
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_CHAR_LIMIT) && srcLen > *dstCharsPtr) {
srcLen = *dstCharsPtr;
}
@@ -2519,7 +2505,6 @@ UtfToUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= 6;
}
@@ -2748,7 +2733,6 @@ Utf32ToUtfProc(
int result, numChars, charLimit = INT_MAX;
int ch = 0, bytesLeft = srcLen % 4;
flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
@@ -2928,7 +2912,6 @@ UtfToUtf32Proc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3026,7 +3009,6 @@ Utf16ToUtfProc(
int result, numChars, charLimit = INT_MAX;
unsigned short ch = 0;
flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
@@ -3115,7 +3097,7 @@ Utf16ToUtfProc(
*dst++ = (ch & 0xFF);
} else if (HIGH_SURROGATE(prev) || HIGH_SURROGATE(ch)) {
dst += Tcl_UniCharToUtf(ch | TCL_COMBINE, dst);
} else if (LOW_SURROGATE(ch) && !PROFILE_TCL8(flags)) {
} else if (LOW_SURROGATE(ch) && (PROFILE_STRICT(flags) || PROFILE_REPLACE(flags))) {
/* Lo surrogate not preceded by Hi surrogate and not tcl8 profile */
if (PROFILE_STRICT(flags)) {
result = TCL_CONVERT_UNKNOWN;
@@ -3216,7 +3198,6 @@ UtfToUtf16Proc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3322,7 +3303,6 @@ UtfToUcs2Proc(
int result, numChars, len;
Tcl_UniChar ch = 0;
flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
srcStart = src;
srcEnd = src + srcLen;
@@ -3445,7 +3425,6 @@ TableToUtfProc(
const unsigned short *pageZero;
TableEncodingData *dataPtr = (TableEncodingData *)clientData;
flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -3588,7 +3567,6 @@ TableFromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3695,7 +3673,6 @@ Iso88591ToUtfProc(
const char *dstEnd, *dstStart;
int result, numChars, charLimit = INT_MAX;
flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -3789,7 +3766,6 @@ Iso88591FromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3937,7 +3913,6 @@ EscapeToUtfProc(
int state, result, numChars, charLimit = INT_MAX;
const char *dstStart, *dstEnd;
flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -4170,7 +4145,6 @@ EscapeFromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -4599,6 +4573,7 @@ TclEncodingProfileIdToName(
{
size_t i;
profileValue &= ENCODING_PROFILE_MASK;
for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
if (profileValue == encodingProfiles[i].value) {
return encodingProfiles[i].name;
@@ -4616,48 +4591,6 @@ TclEncodingProfileIdToName(
return NULL;
}
/*
*------------------------------------------------------------------------
*
* TclEncodingSetProfileFlags --
*
* Maps the flags supported in the encoding C API's to internal flags.
*
* For backward compatibility reasons, TCL_ENCODING_STOPONERROR is
* is mapped to the TCL_ENCODING_PROFILE_STRICT overwriting any profile
* specified.
*
* If no profile or an invalid profile is specified, it is set to
* the default.
*
* Results:
* Internal encoding flag mask.
*
* Side effects:
* None.
*
*------------------------------------------------------------------------
*/
int TclEncodingSetProfileFlags(int flags)
{
if (flags & TCL_ENCODING_STOPONERROR) {
ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT);
} else {
int profile = ENCODING_PROFILE_GET(flags);
switch (profile) {
case TCL_ENCODING_PROFILE_TCL8:
case TCL_ENCODING_PROFILE_STRICT:
case TCL_ENCODING_PROFILE_REPLACE:
break;
case 0: /* Unspecified by caller */
default:
ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_DEFAULT);
break;
}
}
return flags;
}
/*
*------------------------------------------------------------------------
*
+3
View File
@@ -12,6 +12,7 @@
#include "tclInt.h"
#include "tclFileSystem.h"
#include "tclIO.h"
/*
* Declarations for local functions defined in this file:
@@ -1457,6 +1458,8 @@ TclFileTemporaryCmd(
makeTemporary:
chan = TclpOpenTemporaryFile(tempDirObj,tempBaseObj,tempExtObj, nameObj);
ENCODING_PROFILE_SET(((Channel *)chan)->state->inputEncodingFlags, ((Interp *)interp)->flags);
ENCODING_PROFILE_SET(((Channel *)chan)->state->outputEncodingFlags, ((Interp *)interp)->flags);
/*
* If we created pieces of template, get rid of them now.
+2 -4
View File
@@ -1679,12 +1679,10 @@ Tcl_CreateChannel(
statePtr->encoding = Tcl_GetEncoding(NULL, name);
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags,
TCL_ENCODING_PROFILE_DEFAULT);
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, 0);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags,
TCL_ENCODING_PROFILE_DEFAULT);
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, 0);
/*
* Set the channel up initially in AUTO input translation mode to accept
+3
View File
@@ -682,6 +682,9 @@ TclChanCreateObjCmd(
TclChannelPreserve(chan);
chanPtr = (Channel *) chan;
ENCODING_PROFILE_SET(chanPtr->state->inputEncodingFlags, ((Interp *)interp)->flags);
ENCODING_PROFILE_SET(chanPtr->state->outputEncodingFlags, ((Interp *)interp)->flags);
if ((methods & NULLABLE_METHODS) != NULLABLE_METHODS) {
/*
* Some of the nullable methods are not supported. We clone the
+2 -2
View File
@@ -2329,6 +2329,7 @@ typedef struct Interp {
* script in progress has been canceled thereby allowing
* the evaluation stack for the interp to be fully
* unwound.
* Bits 24-32 are reserved to store the default encoding profile.
*
* WARNING: For the sake of some extensions that have made use of former
* internal values, do not re-use the flag values 2 (formerly ERR_IN_PROGRESS)
@@ -2868,7 +2869,7 @@ typedef struct ProcessGlobalValue {
#define ENCODING_PROFILE_SET(flags_, profile_) \
do { \
(flags_) &= ~ENCODING_PROFILE_MASK; \
(flags_) |= profile_; \
(flags_) |= (profile_) & ENCODING_PROFILE_MASK; \
} while (0)
/*
@@ -2893,7 +2894,6 @@ TclEncodingProfileNameToId(Tcl_Interp *interp,
int *profilePtr);
MODULE_SCOPE const char *TclEncodingProfileIdToName(Tcl_Interp *interp,
int profileId);
MODULE_SCOPE int TclEncodingSetProfileFlags(int flags);
MODULE_SCOPE void TclGetEncodingProfiles(Tcl_Interp *interp);
/*
+22 -6
View File
@@ -12,6 +12,7 @@
*/
#include "tclInt.h"
#include "tclIO.h"
/*
* A pointer to a string that holds an initialization script that if non-NULL
@@ -622,8 +623,8 @@ NRInterpCmd(
"children", "create", "debug", "delete",
"eval", "exists", "expose", "hide",
"hidden", "issafe", "invokehidden",
"limit", "marktrusted", "recursionlimit",
"share",
"limit", "marktrusted", "profile",
"recursionlimit", "share",
#ifndef TCL_NO_DEPRECATED
"slaves",
#endif
@@ -634,16 +635,16 @@ NRInterpCmd(
"children", "create", "debug", "delete",
"eval", "exists", "expose",
"hide", "hidden", "issafe",
"invokehidden", "limit", "marktrusted", "recursionlimit",
"share", "target", "transfer",
"invokehidden", "limit", "marktrusted", "profile",
"recursionlimit", "share", "target", "transfer",
NULL
};
enum interpOptionEnum {
OPT_ALIAS, OPT_ALIASES, OPT_BGERROR, OPT_CANCEL,
OPT_CHILDREN, OPT_CREATE, OPT_DEBUG, OPT_DELETE,
OPT_EVAL, OPT_EXISTS, OPT_EXPOSE, OPT_HIDE,
OPT_HIDDEN, OPT_ISSAFE, OPT_INVOKEHID,
OPT_LIMIT, OPT_MARKTRUSTED, OPT_RECLIMIT, OPT_SHARE,
OPT_HIDDEN, OPT_ISSAFE, OPT_INVOKEHID, OPT_LIMIT,
OPT_MARKTRUSTED, OPT_PROFILE, OPT_RECLIMIT, OPT_SHARE,
#ifndef TCL_NO_DEPRECATED
OPT_SLAVES,
#endif
@@ -1033,6 +1034,21 @@ NRInterpCmd(
return TCL_ERROR;
}
return ChildRecursionLimit(interp, childInterp, objc - 3, objv + 3);
case OPT_PROFILE:
if (objc != 2 && objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "?profile?");
return TCL_ERROR;
}
Interp *iPtr = (Interp *)interp;
if (objc == 3) {
int newProfile;
if (TclEncodingProfileNameToId(interp, Tcl_GetString(objv[2]), &newProfile) != TCL_OK) {
return TCL_ERROR;
}
ENCODING_PROFILE_SET(iPtr->flags, newProfile);
}
Tcl_AppendResult(interp, TclEncodingProfileIdToName(NULL, iPtr->flags), NULL);
return TCL_OK;
#ifndef TCL_NO_DEPRECATED
case OPT_SLAVES:
#endif
+6 -6
View File
@@ -1747,7 +1747,7 @@ proc http::OpenSocket {token DoLater} {
fconfigure $sock -translation {auto crlf} \
-buffersize $state(-blocksize)
if {[package vsatisfies [package provide Tcl] 9.0-]} {
fconfigure $sock -profile tcl8
fconfigure $sock -profile replace \
}
##Log socket opened, DONE fconfigure - token $token
}
@@ -2168,7 +2168,7 @@ proc http::Connected {token proto phost srvurl} {
fconfigure $sock -translation [list $trRead crlf] \
-buffersize $state(-blocksize)
if {[package vsatisfies [package provide Tcl] 9.0-]} {
fconfigure $sock -profile tcl8
fconfigure $sock -profile replace \
}
# The following is disallowed in safe interpreters, but the socket is
@@ -2561,7 +2561,7 @@ proc http::ReceiveResponse {token} {
fconfigure $sock -translation [list auto $trWrite] \
-buffersize $state(-blocksize)
if {[package vsatisfies [package provide Tcl] 9.0-]} {
fconfigure $sock -profile tcl8
fconfigure $sock -profile replace \
}
Log ^D$tk begin receiving response - token $token
@@ -4555,7 +4555,7 @@ proc http::Eot {token {reason {}}} {
set enc [CharsetToEncoding $state(charset)]
if {$enc ne "binary"} {
if {[package vsatisfies [package provide Tcl] 9.0-]} {
set state(body) [encoding convertfrom -profile tcl8 $enc $state(body)]
set state(body) [encoding convertfrom -profile replace $enc $state(body)]
} else {
set state(body) [encoding convertfrom $enc $state(body)]
}
@@ -4642,7 +4642,7 @@ proc http::GuessType {token} {
return 0
}
if {[package vsatisfies [package provide Tcl] 9.0-]} {
set state(body) [encoding convertfrom -profile tcl8 $enc $state(body)]
set state(body) [encoding convertfrom -profile replace $enc $state(body)]
} else {
set state(body) [encoding convertfrom $enc $state(body)]
}
@@ -4727,7 +4727,7 @@ proc http::quoteString {string} {
# than [regsub]/[subst]). [Bug 1020491]
if {[package vsatisfies [package provide Tcl] 9.0-]} {
set string [encoding convertto -profile tcl8 $http(-urlencoding) $string]
set string [encoding convertto -profile replace $http(-urlencoding) $string]
} else {
set string [encoding convertto $http(-urlencoding) $string]
}
+1 -1
View File
@@ -307,7 +307,7 @@ proc testfailindex {id converter enc data result failidx {profile default}} {
}
# If this is the default profile, generate a test without specifying profile
if {$profile eq $::encDefaultProfile} {
if {$profile eq "strict"} {
testconvert $id.$enc.default "list \[encoding $converter -failindex idx $enc [list $data]\] \[set idx]" [list $result $failidx]
if {[set enc2 [endianUtf $enc]] ne ""} {
# If utf{16,32}-{le,be}, also do utf{16,32}
+2 -2
View File
@@ -780,7 +780,7 @@ test encoding-24.3 {EscapeFreeProc on open channels} {stdio} {
} [list 3 "乎乞也 (\\u4E4E\\u4E5E\\u4E5F)"]
test encoding-24.4 {Parse valid or invalid utf-8} {
string length [encoding convertfrom utf-8 "\xC0\x80"]
string length [encoding convertfrom -profile tcl8 utf-8 "\xC0\x80"]
} 1
test encoding-24.5 {Parse valid or invalid utf-8} {
string length [encoding convertfrom -profile tcl8 utf-8 "\xC0\x81"]
@@ -822,7 +822,7 @@ test encoding-24.16 {Parse valid or invalid utf-8} -constraints testbytestring -
encoding convertto utf-8 [testbytestring "Z\u4343\x80"]
} -returnCodes 1 -result {expected byte sequence but character 1 was '䍃€' (U+004343)}
test encoding-24.17 {Parse valid or invalid utf-8} -constraints testbytestring -body {
encoding convertto utf-8 [testbytestring "Z\xE0\x80"]
encoding convertto -profile strict utf-8 [testbytestring "Z\xE0\x80"]
} -result "Z\xC3\xA0\xE2\x82\xAC"
test encoding-24.18 {Parse valid or invalid utf-8} -constraints testbytestring -body {
encoding convertto utf-8 [testbytestring "Z\xE0\x80xxxxxx"]
+1 -1
View File
@@ -10,7 +10,7 @@
# List of defined encoding profiles
set encProfiles {tcl8 strict replace}
set encDefaultProfile tcl8; # Should reflect the default from implementation
set encDefaultProfile [interp profile]
# encValidStrings - Table of valid strings.
#
+4 -4
View File
@@ -32,7 +32,7 @@ test interp-1.1 {options for interp command} -returnCodes error -body {
} -result {wrong # args: should be "interp cmd ?arg ...?"}
test interp-1.2 {options for interp command} -returnCodes error -body {
interp frobox
} -result {bad option "frobox": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, recursionlimit, share, target, or transfer}
} -result {bad option "frobox": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, profile, recursionlimit, share, target, or transfer}
test interp-1.3 {options for interp command} {
interp delete
} ""
@@ -50,13 +50,13 @@ test interp-1.6 {options for interp command} -returnCodes error -body {
} -result {wrong # args: should be "interp children ?path?"}
test interp-1.7 {options for interp command} -returnCodes error -body {
interp hello
} -result {bad option "hello": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, recursionlimit, share, target, or transfer}
} -result {bad option "hello": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, profile, recursionlimit, share, target, or transfer}
test interp-1.8 {options for interp command} -returnCodes error -body {
interp -froboz
} -result {bad option "-froboz": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, recursionlimit, share, target, or transfer}
} -result {bad option "-froboz": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, profile, recursionlimit, share, target, or transfer}
test interp-1.9 {options for interp command} -returnCodes error -body {
interp -froboz -safe
} -result {bad option "-froboz": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, recursionlimit, share, target, or transfer}
} -result {bad option "-froboz": must be alias, aliases, bgerror, cancel, children, create, debug, delete, eval, exists, expose, hide, hidden, issafe, invokehidden, limit, marktrusted, profile, recursionlimit, share, target, or transfer}
test interp-1.10 {options for interp command} -returnCodes error -body {
interp target
} -result {wrong # args: should be "interp target path alias"}
+4 -4
View File
@@ -240,11 +240,11 @@ test iocmd-8.7 {fconfigure command} -setup {
file delete $path(test1)
} -body {
set f1 [open $path(test1) w]
fconfigure $f1 -translation lf -eofchar {} -encoding utf-16 -profile tcl8
fconfigure $f1 -translation lf -eofchar {} -encoding utf-16
fconfigure $f1
} -cleanup {
catch {close $f1}
} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -profile tcl8 -translation lf}
} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -profile strict -translation lf}
test iocmd-8.8 {fconfigure command} -setup {
file delete $path(test1)
set x {}
@@ -262,11 +262,11 @@ test iocmd-8.9 {fconfigure command} -setup {
} -body {
set f1 [open $path(test1) w]
fconfigure $f1 -translation binary -buffering none -buffersize 4040 \
-eofchar {} -encoding binary -profile tcl8
-eofchar {} -encoding binary
fconfigure $f1
} -cleanup {
catch {close $f1}
} -result {-blocking 1 -buffering none -buffersize 4040 -encoding iso8859-1 -eofchar {} -profile tcl8 -translation lf}
} -result {-blocking 1 -buffering none -buffersize 4040 -encoding iso8859-1 -eofchar {} -profile strict -translation lf}
test iocmd-8.10 {fconfigure command} -returnCodes error -body {
fconfigure a b
} -result {can not find channel named "a"}