summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-02-10 17:07:12 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-02-10 17:07:12 (GMT)
commite26214c28753b22c398ba4d7196a8afae999ab5a (patch)
tree4a414b531bf1f2880840f04b1a70eb6757a9b38a /generic
parent9d1ba01f11c772a015e3edbfb1ea4ae8e9f148bf (diff)
downloadtcl-e26214c28753b22c398ba4d7196a8afae999ab5a.zip
tcl-e26214c28753b22c398ba4d7196a8afae999ab5a.tar.gz
tcl-e26214c28753b22c398ba4d7196a8afae999ab5a.tar.bz2
Phase out (almost) STRICT and NOCOMPLAIN flags.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCmdAH.c38
-rw-r--r--generic/tclEncoding.c114
-rw-r--r--generic/tclIO.c118
-rw-r--r--generic/tclIO.h3
-rw-r--r--generic/tclInt.h8
5 files changed, 140 insertions, 141 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 05c0887..5fbe27e 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -543,7 +543,7 @@ TclInitEncodingCmd(
* if non-NULL
* - *dataObjPtr is set to the Tcl_Obj containing the data to encode or
* decode
- * - *flagsPtr is set to encoding error handling flags
+ * - *profilePtr is set to encoding error handling profile
* - *failVarPtr is set to -failindex option value or NULL
* On error, all of the above are uninitialized.
*
@@ -556,20 +556,19 @@ EncodingConvertParseOptions (
Tcl_Obj *const objv[], /* Argument objects as passed to command. */
Tcl_Encoding *encPtr, /* Where to store the encoding */
Tcl_Obj **dataObjPtr, /* Where to store ptr to Tcl_Obj containing data */
- int *flagsPtr, /* Bit mask of encoding option flags */
+ int *profilePtr, /* Bit mask of encoding option profile */
Tcl_Obj **failVarPtr /* Where to store -failindex option value */
)
{
static const char *const options[] = {"-profile", "-failindex", NULL};
enum convertfromOptions { PROFILE, FAILINDEX } optIndex;
- int profile;
Tcl_Encoding encoding;
Tcl_Obj *dataObj;
Tcl_Obj *failVarObj;
#if TCL_MAJOR_VERSION > 8 || defined(TCL_NO_DEPRECATED)
- int flags = TCL_ENCODING_STOPONERROR;
+ int profile = TCL_ENCODING_PROFILE_TCL8; /* TODO - default for Tcl9? */
#else
- int flags = TCL_ENCODING_NOCOMPLAIN;
+ int profile = TCL_ENCODING_PROFILE_TCL8;
#endif
/*
@@ -609,14 +608,16 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */
}
switch (optIndex) {
case PROFILE:
- if (TclEncodingProfileParseName(
+ if (TclEncodingProfileNameToId(
interp, Tcl_GetString(objv[argIndex]), &profile)
!= TCL_OK) {
return TCL_ERROR;
}
+#ifdef NOTNEEDED
/* TODO - next line probably not needed as the conversion
functions already take care of mapping profile to flags */
- flags = TclEncodingExternalFlagsToInternal(profile);
+ profile = TclEncodingExternalFlagsToInternal(profile);
+#endif
break;
case FAILINDEX:
failVarObj = objv[argIndex];
@@ -633,7 +634,7 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */
*encPtr = encoding;
*dataObjPtr = dataObj;
- *flagsPtr = flags;
+ *profilePtr = profile;
*failVarPtr = failVarObj;
return TCL_OK;
@@ -676,20 +677,23 @@ EncodingConvertfromObjCmd(
}
/*
- * Convert the string into a byte array in 'ds'
+ * Convert the string into a byte array in 'ds'.
*/
#if !defined(TCL_NO_DEPRECATED) && (TCL_MAJOR_VERSION < 9)
- if (!(flags & TCL_ENCODING_STOPONERROR)) {
+ if (TCL_ENCODING_PROFILE_GET(flags) == TCL_ENCODING_PROFILE_TCL8) {
+ /* Permits high bits to be non-0 in byte array (Tcl 8 style) */
bytesPtr = (char *) Tcl_GetByteArrayFromObj(data, &length);
- } else
+ }
+ else
#endif
- bytesPtr = (char *) TclGetBytesFromObj(interp, data, &length);
+ bytesPtr = (char *) TclGetBytesFromObj(interp, data, &length);
+
if (bytesPtr == NULL) {
return TCL_ERROR;
}
result = Tcl_ExternalToUtfDStringEx(encoding, bytesPtr, length,
flags, &ds);
- if ((!(flags & TCL_ENCODING_NOCOMPLAIN) || ((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT)) && (result != TCL_INDEX_NONE)) {
+ if (result != TCL_INDEX_NONE) {
if (failVarObj != NULL) {
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, Tcl_NewWideIntObj(result), TCL_LEAVE_ERR_MSG) == NULL) {
return TCL_ERROR;
@@ -704,7 +708,8 @@ EncodingConvertfromObjCmd(
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
- } else if (failVarObj != NULL) {
+ }
+ else if (failVarObj != NULL) {
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, Tcl_NewIntObj(-1), TCL_LEAVE_ERR_MSG) == NULL) {
return TCL_ERROR;
}
@@ -769,7 +774,7 @@ EncodingConverttoObjCmd(
stringPtr = TclGetStringFromObj(data, &length);
result = Tcl_UtfToExternalDStringEx(encoding, stringPtr, length,
flags, &ds);
- if ((!(flags & TCL_ENCODING_NOCOMPLAIN) || ((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT)) && (result != TCL_INDEX_NONE)) {
+ if (result != TCL_INDEX_NONE) {
if (failVarObj != NULL) {
/* I hope, wide int will cover size_t data type */
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, Tcl_NewWideIntObj(result), TCL_LEAVE_ERR_MSG) == NULL) {
@@ -788,7 +793,8 @@ EncodingConverttoObjCmd(
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
- } else if (failVarObj != NULL) {
+ }
+ else if (failVarObj != NULL) {
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, Tcl_NewIntObj(-1), TCL_LEAVE_ERR_MSG) == NULL) {
return TCL_ERROR;
}
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 8e42e26..153f8d3 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -188,6 +188,15 @@ static Tcl_Encoding systemEncoding = NULL;
Tcl_Encoding tclIdentityEncoding = NULL;
/*
+ * Names of encoding profiles and corresponding integer values
+ */
+static struct TclEncodingProfiles {
+ const char *name;
+ int value;
+} encodingProfiles[] = {{"tcl8", TCL_ENCODING_PROFILE_TCL8},
+ {"strict", TCL_ENCODING_PROFILE_STRICT}};
+
+/*
* The following variable is used in the sparse matrix code for a
* TableEncoding to represent a page in the table that has no entries.
*/
@@ -1172,7 +1181,7 @@ Tcl_ExternalToUtfDString(
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
- Tcl_ExternalToUtfDStringEx(encoding, src, srcLen, TCL_ENCODING_NOCOMPLAIN, dstPtr);
+ Tcl_ExternalToUtfDStringEx(encoding, src, srcLen, TCL_ENCODING_PROFILE_TCL8, dstPtr);
return Tcl_DStringValue(dstPtr);
}
@@ -2315,11 +2324,17 @@ BinaryProc(
*-------------------------------------------------------------------------
*/
+#ifdef OBSOLETE
#if TCL_MAJOR_VERSION > 8 || defined(TCL_NO_DEPRECATED)
# define STOPONERROR (!(flags & TCL_ENCODING_NOCOMPLAIN) || (flags & TCL_ENCODING_STOPONERROR))
#else
# define STOPONERROR (flags & TCL_ENCODING_STOPONERROR)
#endif
+#endif
+
+
+#define STRICT_PROFILE(flags_) (TCL_ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT)
+#define STOPONERROR STRICT_PROFILE(flags)
static int
UtfToUtfProc(
@@ -2386,10 +2401,11 @@ UtfToUtfProc(
*/
*dst++ = *src++;
- } else if ((UCHAR(*src) == 0xC0) && (src + 1 < srcEnd)
- && (UCHAR(src[1]) == 0x80) && (!(flags & TCL_ENCODING_MODIFIED)
- || ((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT)
- || (flags & ENCODING_FAILINDEX))) {
+ } else if ((UCHAR(*src) == 0xC0) &&
+ (src + 1 < srcEnd) &&
+ (UCHAR(src[1]) == 0x80) &&
+ (!(flags & TCL_ENCODING_MODIFIED)
+ || (STRICT_PROFILE(flags)))) {
/*
* If in input mode, and -strict or -failindex is specified: This is an error.
*/
@@ -2403,7 +2419,8 @@ UtfToUtfProc(
*/
*dst++ = 0;
src += 2;
- } else if (!Tcl_UtfCharComplete(src, srcEnd - src)) {
+ }
+ else if (!Tcl_UtfCharComplete(src, srcEnd - src)) {
/*
* Always check before using TclUtfToUCS4. Not doing can so
* cause it run beyond the end of the buffer! If we happen such an
@@ -2416,10 +2433,10 @@ UtfToUtfProc(
result = TCL_CONVERT_MULTIBYTE;
break;
}
- if (((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT) || (flags & ENCODING_FAILINDEX)) {
- result = TCL_CONVERT_SYNTAX;
- break;
- }
+ if (STRICT_PROFILE(flags)) {
+ result = TCL_CONVERT_SYNTAX;
+ break;
+ }
ch = UCHAR(*src++);
} else {
char chbuf[2];
@@ -2427,12 +2444,13 @@ UtfToUtfProc(
TclUtfToUCS4(chbuf, &ch);
}
dst += Tcl_UniCharToUtf(ch, dst);
- } else {
+ }
+ else {
int low;
const char *saveSrc = src;
size_t len = TclUtfToUCS4(src, &ch);
if ((len < 2) && (ch != 0) && (flags & TCL_ENCODING_MODIFIED)
- && (((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT))) {
+ && STRICT_PROFILE(flags)) {
result = TCL_CONVERT_SYNTAX;
break;
}
@@ -2475,8 +2493,9 @@ UtfToUtfProc(
result = TCL_CONVERT_UNKNOWN;
src = saveSrc;
break;
- } else if (((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT)
- && (flags & TCL_ENCODING_MODIFIED) && ((ch & ~0x7FF) == 0xD800)) {
+ } else if (STRICT_PROFILE(flags) &&
+ (flags & TCL_ENCODING_MODIFIED) &&
+ ((ch & ~0x7FF) == 0xD800)) {
result = TCL_CONVERT_SYNTAX;
src = saveSrc;
break;
@@ -2567,8 +2586,8 @@ Utf32ToUtfProc(
} else {
ch = (src[0] & 0xFF) << 24 | (src[1] & 0xFF) << 16 | (src[2] & 0xFF) << 8 | (src[3] & 0xFF);
}
- if ((unsigned)ch > 0x10FFFF || (((flags & TCL_ENCODING_STRICT) == TCL_ENCODING_STRICT)
- && ((ch & ~0x7FF) == 0xD800))) {
+ if ((unsigned)ch > 0x10FFFF
+ || (STRICT_PROFILE(flags) && ((ch & ~0x7FF) == 0xD800))) {
if (STOPONERROR) {
result = TCL_CONVERT_SYNTAX;
break;
@@ -4095,34 +4114,27 @@ InitializeEncodingSearchPath(
*
* TclEncodingProfileParseName --
*
- * Maps an encoding profile name to its integer equivalent.
+ * Maps an encoding profile name to its integer equivalent.
*
* Results:
- * TCL_OK on success or TCL_ERROR on failure.
+ * TCL_OK on success or TCL_ERROR on failure.
*
* Side effects:
- * Returns the profile enum value in *profilePtr
+ * Returns the profile enum value in *profilePtr
*
*------------------------------------------------------------------------
*/
int
-TclEncodingProfileParseName(
+TclEncodingProfileNameToId(
Tcl_Interp *interp, /* For error messages. May be NULL */
const char *profileName, /* Name of profile */
int *profilePtr) /* Output */
{
- /* NOTE: Order in arrays must match !!! */
- static const char *const profileNames[] = {"", "tcl8", "strict", NULL};
- static int profileFlags[] = {
- TCL_ENCODING_PROFILE_DEFAULT,
- TCL_ENCODING_PROFILE_TCL8,
- TCL_ENCODING_PROFILE_STRICT,
- };
int i;
- for (i = 0; i < sizeof(profileNames) / sizeof(profileNames[0]); ++i) {
- if (!strcmp(profileName, profileNames[i])) {
- *profilePtr = profileFlags[i];
+ for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
+ if (!strcmp(profileName, encodingProfiles[i].name)) {
+ *profilePtr = encodingProfiles[i].value;
return TCL_OK;
}
}
@@ -4130,13 +4142,52 @@ TclEncodingProfileParseName(
Tcl_SetObjResult(
interp,
Tcl_ObjPrintf(
- "bad profile \"%s\". Must be \"\", \"tcl8\" or \"strict\".",
+ "bad profile \"%s\". Must be \"tcl8\" or \"strict\".",
profileName));
Tcl_SetErrorCode(
interp, "TCL", "ENCODING", "PROFILE", profileName, NULL);
}
return TCL_ERROR;
}
+
+/*
+ *------------------------------------------------------------------------
+ *
+ * TclEncodingProfileValueToName --
+ *
+ * Maps an encoding profile value to its name.
+ *
+ * Results:
+ * Pointer to the name or NULL on failure. Caller must not make
+ * not modify the string and must make a copy to hold on to it.
+ *
+ * Side effects:
+ * None.
+ *------------------------------------------------------------------------
+ */
+const char *
+TclEncodingProfileIdToName(
+ Tcl_Interp *interp, /* For error messages. May be NULL */
+ int profileValue) /* Profile #define value */
+{
+ int i;
+
+ for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
+ if (profileValue == encodingProfiles[i].value) {
+ return encodingProfiles[i].name;
+ }
+ }
+ if (interp) {
+ Tcl_SetObjResult(
+ interp,
+ Tcl_ObjPrintf(
+ "Internal error. Bad profile id \"%d\".",
+ profileValue));
+ Tcl_SetErrorCode(
+ interp, "TCL", "ENCODING", "PROFILEID", NULL);
+ }
+ return NULL;
+}
/*
*------------------------------------------------------------------------
@@ -4179,6 +4230,7 @@ int TclEncodingExternalFlagsToInternal(int flags)
case TCL_ENCODING_PROFILE_STRICT:
flags |= TCL_ENCODING_STRICT;
break;
+ case 0: /* Unspecified by caller */
default:
/* TODO - clean this up once default mechanisms settled */
TCL_ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_DEFAULT);
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 0152740..49f4257 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -1700,8 +1700,12 @@ Tcl_CreateChannel(
}
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags,
+ TCL_ENCODING_PROFILE_DEFAULT);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags,
+ TCL_ENCODING_PROFILE_DEFAULT);
/*
* Set the channel up initially in AUTO input translation mode to accept
@@ -4394,21 +4398,6 @@ Write(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->outputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->outputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->outputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->outputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
- /*
* Write the terminated escape sequence even if srcLen is 0.
*/
@@ -4733,21 +4722,6 @@ Tcl_GetsObj(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
- /*
* Object used by FilterInputBytes to keep track of how much data has been
* consumed from the channel buffers.
*/
@@ -5528,21 +5502,6 @@ FilterInputBytes(
}
gsPtr->state = statePtr->inputEncodingState;
- /*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
result = Tcl_ExternalToUtf(NULL, gsPtr->encoding, raw, rawLen,
statePtr->inputEncodingFlags | TCL_ENCODING_NO_TERMINATE,
&statePtr->inputEncodingState, dst, spaceLeft, &gsPtr->rawRead,
@@ -6349,21 +6308,6 @@ ReadChars(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
- /*
* This routine is burdened with satisfying several constraints. It cannot
* append more than 'charsToRead` chars onto objPtr. This is measured
* after encoding and translation transformations are completed. There is
@@ -8065,16 +8009,18 @@ Tcl_GetChannelOption(
}
}
if (len == 0 || HaveOpt(1, "-encodingprofile")) {
+ int profile;
+ const char *profileName;
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-encodingprofile");
}
- if (flags & CHANNEL_ENCODING_STRICT) {
- Tcl_DStringAppendElement(dsPtr, "strict");
- } else if (flags & CHANNEL_ENCODING_NOCOMPLAIN) {
- Tcl_DStringAppendElement(dsPtr, "tcl8");
- } else {
- Tcl_DStringAppendElement(dsPtr, "");
+ /* Note currently input and output profiles are same */
+ profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
+ profileName = TclEncodingProfileIdToName(interp, profile);
+ if (profileName == NULL) {
+ return TCL_ERROR;
}
+ Tcl_DStringAppendElement(dsPtr, profileName);
if (len > 0) {
return TCL_OK;
}
@@ -8293,6 +8239,7 @@ Tcl_SetChannelOption(
return TCL_OK;
} else if (HaveOpt(2, "-encoding")) {
Tcl_Encoding encoding;
+ int profile;
if ((newValue[0] == '\0') || (strcmp(newValue, "binary") == 0)) {
encoding = NULL;
@@ -8317,9 +8264,12 @@ Tcl_SetChannelOption(
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = encoding;
statePtr->inputEncodingState = NULL;
+ profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
statePtr->inputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
UpdateInterest(chanPtr);
return TCL_OK;
@@ -8380,28 +8330,11 @@ Tcl_SetChannelOption(
return TCL_OK;
} else if (HaveOpt(1, "-encodingprofile")) {
int profile;
- if (TclEncodingProfileParseName(interp, newValue, &profile) != TCL_OK) {
+ if (TclEncodingProfileNameToId(interp, newValue, &profile) != TCL_OK) {
return TCL_ERROR;
}
- switch (profile) {
- case TCL_ENCODING_PROFILE_TCL8:
- ResetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- SetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- break;
- case TCL_ENCODING_PROFILE_STRICT:
- ResetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- SetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- break;
- /* TODO - clean up this DEFAULT handling once channel flags fixed */
-#if TCL_ENCODING_PROFILE_DEFAULT != TCL_ENCODING_PROFILE_TCL8 \
- && TCL_ENCODING_PROFILE_DEFAULT != TCL_ENCODING_PROFILE_STRICT
- case TCL_ENCODING_PROFILE_DEFAULT: /* FALLTHRU */
-#endif
- default:
- ResetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- ResetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- break;
- }
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile);
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
return TCL_OK;
} else if (HaveOpt(1, "-translation")) {
@@ -9493,12 +9426,17 @@ TclCopyChannel(
* of the bytes themselves.
*/
+ /*
+ * TODO - should really only allow lossless profiles. Below reflects
+ * Tcl 8.7 alphas prior to encoding profiles
+ */
+
moveBytes = inStatePtr->inEofChar == '\0' /* No eofChar to stop input */
&& inStatePtr->inputTranslation == TCL_TRANSLATE_LF
&& outStatePtr->outputTranslation == TCL_TRANSLATE_LF
&& inStatePtr->encoding == outStatePtr->encoding
- && (inStatePtr->flags & TCL_ENCODING_STRICT) != TCL_ENCODING_STRICT
- && outStatePtr->flags & TCL_ENCODING_NOCOMPLAIN;
+ && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT
+ && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8;
/*
* Allocate a new CopyState to maintain info about the current copy in
@@ -9826,8 +9764,8 @@ CopyData(
inBinary = (inStatePtr->encoding == NULL);
outBinary = (outStatePtr->encoding == NULL);
sameEncoding = inStatePtr->encoding == outStatePtr->encoding
- && (inStatePtr->flags & TCL_ENCODING_STRICT) != TCL_ENCODING_STRICT
- && outStatePtr->flags & TCL_ENCODING_NOCOMPLAIN;
+ && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT
+ && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8;
if (!(inBinary || sameEncoding)) {
TclNewObj(bufObj);
diff --git a/generic/tclIO.h b/generic/tclIO.h
index a69e990..3f2feee 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -275,16 +275,17 @@ typedef struct ChannelState {
* encountered an encoding error */
#define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is
* being used. */
+#ifdef APN
#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option
* -nocomplainencoding is set to 1 */
#define CHANNEL_ENCODING_STRICT (1<<18) /* set if option
* -strictencoding is set to 1 */
+#endif
#define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed.
* Its structures are still live and
* usable, but it may not be closed
* again from within the close
* handler. */
-#define ENCODING_FAILINDEX (1<<20) /* Internal flag, fail on Invalid bytes only */
#define CHANNEL_CLOSEDWRITE (1<<21) /* Channel write side has been closed.
* No further Tcl-level write IO on
* the channel is allowed. */
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 2b491d6..4b6303d 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2885,9 +2885,11 @@ MODULE_SCOPE TclPlatformType tclPlatform;
MODULE_SCOPE Tcl_Encoding tclIdentityEncoding;
MODULE_SCOPE int
-TclEncodingProfileParseName(Tcl_Interp *interp,
- const char *profileName,
- int *profilePtr);
+TclEncodingProfileNameToId(Tcl_Interp *interp,
+ const char *profileName,
+ int *profilePtr);
+MODULE_SCOPE const char *TclEncodingProfileIdToName(Tcl_Interp *interp,
+ int profileId);
MODULE_SCOPE int TclEncodingExternalFlagsToInternal(int flags);
/*