Skip to content

Commit

Permalink
Changed CHANNEL_PROFILE_* to ENCODING_PROFILE_* and moved out of tclI…
Browse files Browse the repository at this point in the history
…O.h. See below.

For whatever reason, these macros were renamed and moved to tclIO.h post-660. This is
inappropriate as those macros deal with *encoding* flags, not *channel* flags and have
relevance outside of I/O making their renaming inappropriate. Further putting them in tclIO.h
forces inclusion of that header in modules that do not otherwise need that header.
  • Loading branch information
apnadkarni committed May 3, 2023
1 parent 41aa17e commit 81b4fa2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
9 changes: 6 additions & 3 deletions generic/tcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1969,15 +1969,18 @@ typedef struct Tcl_EncodingType {
#define TCL_ENCODING_CHAR_LIMIT 0x10
/* Internal use bits, do not define bits in this space. See above comment */
#define TCL_ENCODING_INTERNAL_USE_MASK 0xFF00
/* Reserve top byte for profile values (disjoint, not a mask) */
/*
* Reserve top byte for profile values (disjoint, not a mask). In case of
* changes, ensure ENCODING_PROFILE_* macros in tclInt.h are modified if
* necessary.
*/
#define TCL_ENCODING_PROFILE_TCL8 0x01000000
#define TCL_ENCODING_PROFILE_STRICT 0x02000000
#define TCL_ENCODING_PROFILE_REPLACE 0x03000000
/* Still being argued - For Tcl9, is the default strict? TODO */
#if TCL_MAJOR_VERSION < 9
#define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8
#else
#define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8 /* STRICT? REPLACE? TODO */
#define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8
#endif

/*
Expand Down
21 changes: 10 additions & 11 deletions generic/tclEncoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

#include "tclInt.h"
#include "tclIO.h"

typedef size_t (LengthProc)(const char *src);

Expand Down Expand Up @@ -200,16 +199,16 @@ static struct TclEncodingProfiles {
{"tcl8", TCL_ENCODING_PROFILE_TCL8},
};
#define PROFILE_TCL8(flags_) \
((CHANNEL_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_TCL8) \
|| (CHANNEL_PROFILE_GET(flags_) == 0 \
((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_) \
((CHANNEL_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) \
|| (CHANNEL_PROFILE_GET(flags_) == 0 \
((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) \
|| (ENCODING_PROFILE_GET(flags_) == 0 \
&& TCL_ENCODING_PROFILE_DEFAULT == TCL_ENCODING_PROFILE_STRICT))
#define PROFILE_REPLACE(flags_) \
((CHANNEL_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) \
|| (CHANNEL_PROFILE_GET(flags_) == 0 \
((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) \
|| (ENCODING_PROFILE_GET(flags_) == 0 \
&& TCL_ENCODING_PROFILE_DEFAULT == TCL_ENCODING_PROFILE_REPLACE))

#define UNICODE_REPLACE_CHAR ((Tcl_UniChar)0xFFFD)
Expand Down Expand Up @@ -2542,7 +2541,7 @@ UtfToUtfProc(
memset(dst, 0xff, dstLen);
#endif

profile = CHANNEL_PROFILE_GET(flags);
profile = ENCODING_PROFILE_GET(flags);
for (numChars = 0; src < srcEnd && numChars <= charLimit; numChars++) {

if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) {
Expand Down Expand Up @@ -4642,17 +4641,17 @@ TclEncodingProfileIdToName(
int TclEncodingSetProfileFlags(int flags)
{
if (flags & TCL_ENCODING_STOPONERROR) {
CHANNEL_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT);
ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT);
} else {
int profile = CHANNEL_PROFILE_GET(flags);
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:
CHANNEL_PROFILE_SET(flags, TCL_ENCODING_PROFILE_DEFAULT);
ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_DEFAULT);
break;
}
}
Expand Down
44 changes: 22 additions & 22 deletions generic/tclIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,11 +1679,11 @@ Tcl_CreateChannel(
statePtr->encoding = Tcl_GetEncoding(NULL, name);
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags,
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags,
TCL_ENCODING_PROFILE_DEFAULT);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags,
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags,
TCL_ENCODING_PROFILE_DEFAULT);

/*
Expand Down Expand Up @@ -7974,7 +7974,7 @@ Tcl_GetChannelOption(
Tcl_DStringAppendElement(dsPtr, "-profile");
}
/* Note currently input and output profiles are same */
profile = CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags);
profile = ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
profileName = TclEncodingProfileIdToName(interp, profile);
if (profileName == NULL) {
return TCL_ERROR;
Expand Down Expand Up @@ -8169,11 +8169,11 @@ Tcl_SetChannelOption(

if ((newValue[0] == '\0') || (strcmp(newValue, "binary") == 0)) {
encoding = Tcl_GetEncoding(NULL, "iso8859-1");
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->inputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->outputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
} else {
encoding = Tcl_GetEncoding(interp, newValue);
Expand All @@ -8196,12 +8196,12 @@ Tcl_SetChannelOption(
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = encoding;
statePtr->inputEncodingState = NULL;
profile = CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags);
profile = ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
statePtr->inputEncodingFlags = TCL_ENCODING_START;
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags, profile);
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
UpdateInterest(chanPtr);
return TCL_OK;
Expand Down Expand Up @@ -8244,8 +8244,8 @@ Tcl_SetChannelOption(
if (TclEncodingProfileNameToId(interp, newValue, &profile) != TCL_OK) {
return TCL_ERROR;
}
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags, profile);
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags, profile);
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile);
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
return TCL_OK;
} else if (HaveOpt(1, "-translation")) {
Expand Down Expand Up @@ -8283,11 +8283,11 @@ Tcl_SetChannelOption(
statePtr->inEofChar = 0;
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = Tcl_GetEncoding(NULL, "iso8859-1");
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->inputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->outputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
} else if (strcmp(readMode, "lf") == 0) {
translation = TCL_TRANSLATE_LF;
Expand Down Expand Up @@ -8338,11 +8338,11 @@ Tcl_SetChannelOption(
statePtr->outputTranslation = TCL_TRANSLATE_LF;
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = Tcl_GetEncoding(NULL, "iso8859-1");
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->inputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags
,ENCODING_PROFILE_GET(statePtr->outputEncodingFlags)
|TCL_ENCODING_PROFILE_STRICT);
} else if (strcmp(writeMode, "lf") == 0) {
statePtr->outputTranslation = TCL_TRANSLATE_LF;
Expand Down Expand Up @@ -10269,8 +10269,8 @@ Lossless(
(
toRead == -1
&& inStatePtr->encoding == outStatePtr->encoding
&& CHANNEL_PROFILE_GET(inStatePtr->inputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8
&& CHANNEL_PROFILE_GET(outStatePtr->inputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8
&& ENCODING_PROFILE_GET(inStatePtr->inputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8
&& ENCODING_PROFILE_GET(outStatePtr->inputEncodingFlags) == TCL_ENCODING_PROFILE_TCL8
)
);
}
Expand Down
7 changes: 0 additions & 7 deletions generic/tclIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,6 @@ typedef struct ChannelState {
#define CHANNEL_CLOSEDWRITE (1<<21) /* Channel write side has been closed.
* No further Tcl-level write IO on
* the channel is allowed. */
#define CHANNEL_PROFILE_MASK 0xFF000000
#define CHANNEL_PROFILE_GET(flags_) ((flags_) & CHANNEL_PROFILE_MASK)
#define CHANNEL_PROFILE_SET(flags_, profile_) \
do { \
(flags_) &= ~CHANNEL_PROFILE_MASK; \
(flags_) |= profile_; \
} while (0)

/*
* The length of time to wait between synthetic timer events. Must be zero or
Expand Down
16 changes: 16 additions & 0 deletions generic/tclInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,22 @@ typedef struct ProcessGlobalValue {
#define TCL_PARSE_NO_UNDERSCORE 128
/* Reject underscore digit separator */


/*
*----------------------------------------------------------------------
* Internal convenience macros for manipulating encoding flags. See
* TCL_ENCODING_PROFILE_* in tcl.h
*----------------------------------------------------------------------
*/

#define ENCODING_PROFILE_MASK 0xFF000000
#define ENCODING_PROFILE_GET(flags_) ((flags_) & ENCODING_PROFILE_MASK)
#define ENCODING_PROFILE_SET(flags_, profile_) \
do { \
(flags_) &= ~ENCODING_PROFILE_MASK; \
(flags_) |= profile_; \
} while (0)

/*
*----------------------------------------------------------------
* Variables shared among Tcl modules but not used by the outside world.
Expand Down

0 comments on commit 81b4fa2

Please sign in to comment.