summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-30 13:04:12 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-30 13:04:12 (GMT)
commitee66478056af217424f2052723fbd89ee0d0f933 (patch)
tree20673cfe4002fa7170684a2d040508f6534c2b22
parent56f2fc4f042a67bb4211d55850c10c1639795dd6 (diff)
downloadtcl-ee66478056af217424f2052723fbd89ee0d0f933.zip
tcl-ee66478056af217424f2052723fbd89ee0d0f933.tar.gz
tcl-ee66478056af217424f2052723fbd89ee0d0f933.tar.bz2
Simplify the use of HaveVersion() in Channel handling. Nothing functional, only code clean-up.
-rw-r--r--generic/tclIO.c100
-rw-r--r--generic/tclIOCmd.c2
-rw-r--r--generic/tclIORTrans.c38
3 files changed, 35 insertions, 105 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index ff04636..8ea70e7 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -204,8 +204,6 @@ static Tcl_Encoding GetBinaryEncoding();
static void FreeBinaryEncoding(ClientData clientData);
static Tcl_HashTable * GetChannelTable(Tcl_Interp *interp);
static int GetInput(Channel *chanPtr);
-static int HaveVersion(const Tcl_ChannelType *typePtr,
- Tcl_ChannelTypeVersion minimumVersion);
static void PeekAhead(Channel *chanPtr, char **dstEndPtr,
GetsState *gsPtr);
static int ReadBytes(ChannelState *statePtr, Tcl_Obj *objPtr,
@@ -471,9 +469,8 @@ ChanSeek(
* type and non-NULL.
*/
- if (HaveVersion(chanPtr->typePtr, TCL_CHANNEL_VERSION_3) &&
- chanPtr->typePtr->wideSeekProc != NULL) {
- return chanPtr->typePtr->wideSeekProc(chanPtr->instanceData,
+ if (Tcl_ChannelWideSeekProc(chanPtr->typePtr) != NULL) {
+ return Tcl_ChannelWideSeekProc(chanPtr->typePtr)(chanPtr->instanceData,
offset, mode, errnoPtr);
}
@@ -482,7 +479,7 @@ ChanSeek(
return Tcl_LongAsWide(-1);
}
- return Tcl_LongAsWide(chanPtr->typePtr->seekProc(chanPtr->instanceData,
+ return Tcl_LongAsWide(Tcl_ChannelSeekProc(chanPtr->typePtr)(chanPtr->instanceData,
Tcl_WideAsLong(offset), mode, errnoPtr));
}
@@ -4175,7 +4172,7 @@ WillWrite(
{
int inputBuffered;
- if ((chanPtr->typePtr->seekProc != NULL) &&
+ if ((Tcl_ChannelSeekProc(chanPtr->typePtr) != NULL) &&
((inputBuffered = Tcl_InputBuffered((Tcl_Channel) chanPtr)) > 0)){
int ignore;
@@ -4194,7 +4191,7 @@ WillRead(
Tcl_SetErrno(EINVAL);
return -1;
}
- if ((chanPtr->typePtr->seekProc != NULL)
+ if ((Tcl_ChannelSeekProc(chanPtr->typePtr) != NULL)
&& (Tcl_OutputBuffered((Tcl_Channel) chanPtr) > 0)) {
/*
@@ -6933,7 +6930,7 @@ Tcl_Seek(
* defined. This means that the channel does not support seeking.
*/
- if (chanPtr->typePtr->seekProc == NULL) {
+ if (Tcl_ChannelSeekProc(chanPtr->typePtr) == NULL) {
Tcl_SetErrno(EINVAL);
return Tcl_LongAsWide(-1);
}
@@ -7097,7 +7094,7 @@ Tcl_Tell(
* defined. This means that the channel does not support seeking.
*/
- if (chanPtr->typePtr->seekProc == NULL) {
+ if (Tcl_ChannelSeekProc(chanPtr->typePtr) == NULL) {
Tcl_SetErrno(EINVAL);
return Tcl_LongAsWide(-1);
}
@@ -10427,49 +10424,15 @@ Tcl_ChannelVersion(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (chanTypePtr->version == TCL_CHANNEL_VERSION_2) {
- return TCL_CHANNEL_VERSION_2;
- } else if (chanTypePtr->version == TCL_CHANNEL_VERSION_3) {
- return TCL_CHANNEL_VERSION_3;
- } else if (chanTypePtr->version == TCL_CHANNEL_VERSION_4) {
- return TCL_CHANNEL_VERSION_4;
- } else if (chanTypePtr->version == TCL_CHANNEL_VERSION_5) {
- return TCL_CHANNEL_VERSION_5;
- } else {
+ if ((chanTypePtr->version < TCL_CHANNEL_VERSION_2)
+ || (chanTypePtr->version > TCL_CHANNEL_VERSION_5)) {
/*
* In <v2 channel versions, the version field is occupied by the
* Tcl_DriverBlockModeProc
*/
-
return TCL_CHANNEL_VERSION_1;
}
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * HaveVersion --
- *
- * Return whether a channel type is (at least) of a given version.
- *
- * Results:
- * True if the minimum version is exceeded by the version actually
- * present.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-HaveVersion(
- const Tcl_ChannelType *chanTypePtr,
- Tcl_ChannelTypeVersion minimumVersion)
-{
- Tcl_ChannelTypeVersion actualVersion = Tcl_ChannelVersion(chanTypePtr);
-
- return (PTR2INT(actualVersion)) >= (PTR2INT(minimumVersion));
+ return chanTypePtr->version;
}
/*
@@ -10492,15 +10455,14 @@ Tcl_ChannelBlockModeProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_2)) {
- return chanTypePtr->blockModeProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_2) {
+ /*
+ * The v1 structure had the blockModeProc in a different place.
+ */
+ return (Tcl_DriverBlockModeProc *) chanTypePtr->version;
}
- /*
- * The v1 structure had the blockModeProc in a different place.
- */
-
- return (Tcl_DriverBlockModeProc *) chanTypePtr->version;
+ return chanTypePtr->blockModeProc;
}
/*
@@ -10740,10 +10702,10 @@ Tcl_ChannelFlushProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_2)) {
- return chanTypePtr->flushProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_2) {
+ return NULL;
}
- return NULL;
+ return chanTypePtr->flushProc;
}
/*
@@ -10767,10 +10729,10 @@ Tcl_ChannelHandlerProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_2)) {
- return chanTypePtr->handlerProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_2) {
+ return NULL;
}
- return NULL;
+ return chanTypePtr->handlerProc;
}
/*
@@ -10794,10 +10756,10 @@ Tcl_ChannelWideSeekProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_3)) {
- return chanTypePtr->wideSeekProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_3) {
+ return NULL;
}
- return NULL;
+ return chanTypePtr->wideSeekProc;
}
/*
@@ -10822,10 +10784,10 @@ Tcl_ChannelThreadActionProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_4)) {
- return chanTypePtr->threadActionProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_4) {
+ return NULL;
}
- return NULL;
+ return chanTypePtr->threadActionProc;
}
/*
@@ -11137,10 +11099,10 @@ Tcl_ChannelTruncateProc(
const Tcl_ChannelType *chanTypePtr)
/* Pointer to channel type. */
{
- if (HaveVersion(chanTypePtr, TCL_CHANNEL_VERSION_5)) {
- return chanTypePtr->truncateProc;
+ if (Tcl_ChannelVersion(chanTypePtr) < TCL_CHANNEL_VERSION_5) {
+ return NULL;
}
- return NULL;
+ return chanTypePtr->truncateProc;
}
/*
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index 834f225..af1295f 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -713,7 +713,7 @@ Tcl_CloseObjCmd(
/*
* Special handling is needed if and only if the channel mode supports
* more than the direction to close. Because if the close the last
- * direction suppported we can and will go through the regular
+ * direction supported we can and will go through the regular
* process.
*/
diff --git a/generic/tclIORTrans.c b/generic/tclIORTrans.c
index af86ba5..27a938d 100644
--- a/generic/tclIORTrans.c
+++ b/generic/tclIORTrans.c
@@ -27,10 +27,6 @@
#define EOK 0
#endif
-/* DUPLICATE of HaveVersion() in tclIO.c // TODO - MODULE_SCOPE */
-static int HaveVersion(const Tcl_ChannelType *typePtr,
- Tcl_ChannelTypeVersion minimumVersion);
-
/*
* Signatures of all functions used in the C layer of the reflection.
*/
@@ -1386,16 +1382,15 @@ ReflectSeekWide(
* non-NULL...
*/
- if (HaveVersion(parent->typePtr, TCL_CHANNEL_VERSION_3) &&
- parent->typePtr->wideSeekProc != NULL) {
- curPos = parent->typePtr->wideSeekProc(parent->instanceData, offset,
+ if (Tcl_ChannelWideSeekProc(parent->typePtr) != NULL) {
+ curPos = Tcl_ChannelWideSeekProc(parent->typePtr)(parent->instanceData, offset,
seekMode, errorCodePtr);
} else if (offset < Tcl_LongAsWide(LONG_MIN) ||
offset > Tcl_LongAsWide(LONG_MAX)) {
*errorCodePtr = EOVERFLOW;
curPos = Tcl_LongAsWide(-1);
} else {
- curPos = Tcl_LongAsWide(parent->typePtr->seekProc(
+ curPos = Tcl_LongAsWide(Tcl_ChannelSeekProc(parent->typePtr)(
parent->instanceData, Tcl_WideAsLong(offset), seekMode,
errorCodePtr));
}
@@ -3391,33 +3386,6 @@ TransformLimit(
return 1;
}
-/* DUPLICATE of HaveVersion() in tclIO.c
- *----------------------------------------------------------------------
- *
- * HaveVersion --
- *
- * Return whether a channel type is (at least) of a given version.
- *
- * Results:
- * True if the minimum version is exceeded by the version actually
- * present.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-HaveVersion(
- const Tcl_ChannelType *chanTypePtr,
- Tcl_ChannelTypeVersion minimumVersion)
-{
- Tcl_ChannelTypeVersion actualVersion = Tcl_ChannelVersion(chanTypePtr);
-
- return PTR2INT(actualVersion) >= PTR2INT(minimumVersion);
-}
-
/*
* Local Variables:
* mode: c