summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclAssembly.c2
-rw-r--r--generic/tclCmdIL.c14
-rw-r--r--generic/tclCompCmdsGR.c24
-rw-r--r--generic/tclCompCmdsSZ.c41
-rw-r--r--generic/tclExecute.c31
-rw-r--r--generic/tclInt.h5
-rw-r--r--generic/tclUtil.c42
7 files changed, 66 insertions, 93 deletions
diff --git a/generic/tclAssembly.c b/generic/tclAssembly.c
index 85bc8b9..5db2676 100644
--- a/generic/tclAssembly.c
+++ b/generic/tclAssembly.c
@@ -2262,7 +2262,7 @@ GetListIndexOperand(
* when list size limits grow.
*/
status = TclIndexEncode(interp, value,
- TCL_INDEX_BEFORE,TCL_INDEX_BEFORE, result);
+ TCL_INDEX_NONE,TCL_INDEX_NONE, result);
Tcl_DecrRefCount(value);
*tokenPtrPtr = TokenAfter(tokenPtr);
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 03867b2..34e9382 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -3239,11 +3239,11 @@ Tcl_LsearchObjCmd(
for (j=0 ; j<sortInfo.indexc ; j++) {
int encoded = 0;
- if (TclIndexEncode(interp, indices[j], TCL_INDEX_BEFORE,
- TCL_INDEX_BEFORE, &encoded) != TCL_OK) {
+ if (TclIndexEncode(interp, indices[j], TCL_INDEX_NONE,
+ TCL_INDEX_NONE, &encoded) != TCL_OK) {
result = TCL_ERROR;
}
- if (encoded == TCL_INDEX_BEFORE) {
+ if (encoded == TCL_INDEX_NONE) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"index \"%s\" cannot select an element "
"from any list", Tcl_GetString(indices[j])));
@@ -3958,9 +3958,9 @@ Tcl_LsortObjCmd(
for (j=0 ; j<indexc ; j++) {
int encoded = 0;
int result = TclIndexEncode(interp, indexv[j],
- TCL_INDEX_BEFORE, TCL_INDEX_BEFORE, &encoded);
+ TCL_INDEX_NONE, TCL_INDEX_NONE, &encoded);
- if ((result == TCL_OK) && (encoded == TCL_INDEX_BEFORE)) {
+ if ((result == TCL_OK) && (encoded == TCL_INDEX_NONE)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"index \"%s\" cannot select an element "
"from any list", Tcl_GetString(indexv[j])));
@@ -4049,8 +4049,8 @@ Tcl_LsortObjCmd(
}
for (j=0 ; j<sortInfo.indexc ; j++) {
/* Prescreened values, no errors or out of range possible */
- TclIndexEncode(NULL, indexv[j], TCL_INDEX_BEFORE,
- TCL_INDEX_BEFORE, &sortInfo.indexv[j]);
+ TclIndexEncode(NULL, indexv[j], TCL_INDEX_NONE,
+ TCL_INDEX_NONE, &sortInfo.indexv[j]);
}
}
diff --git a/generic/tclCompCmdsGR.c b/generic/tclCompCmdsGR.c
index f9cf3d8..26e9c87 100644
--- a/generic/tclCompCmdsGR.c
+++ b/generic/tclCompCmdsGR.c
@@ -1089,8 +1089,8 @@ TclCompileLindexCmd(
}
idxTokenPtr = TokenAfter(valTokenPtr);
- if (TclGetIndexFromToken(idxTokenPtr, TCL_INDEX_BEFORE, TCL_INDEX_BEFORE,
- &idx) == TCL_OK) {
+ if (TclGetIndexFromToken(idxTokenPtr, TCL_INDEX_NONE,
+ TCL_INDEX_NONE, &idx) == TCL_OK) {
/*
* The idxTokenPtr parsed as a valid index value and was
* encoded as expected by INST_LIST_INDEX_IMM.
@@ -1318,8 +1318,8 @@ TclCompileLrangeCmd(
listTokenPtr = TokenAfter(parsePtr->tokenPtr);
tokenPtr = TokenAfter(listTokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_AFTER,
- &idx1) != TCL_OK) {
+ if ((TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_NONE,
+ &idx1) != TCL_OK) || (idx1 == TCL_INDEX_NONE)) {
return TCL_ERROR;
}
/*
@@ -1328,7 +1328,7 @@ TclCompileLrangeCmd(
*/
tokenPtr = TokenAfter(tokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_BEFORE, TCL_INDEX_END,
+ if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_NONE, TCL_INDEX_END,
&idx2) != TCL_OK) {
return TCL_ERROR;
}
@@ -1483,13 +1483,13 @@ TclCompileLreplaceCmd(
listTokenPtr = TokenAfter(parsePtr->tokenPtr);
tokenPtr = TokenAfter(listTokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_AFTER,
+ if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_NONE,
&idx1) != TCL_OK) {
return TCL_ERROR;
}
tokenPtr = TokenAfter(tokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_BEFORE, TCL_INDEX_END,
+ if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_NONE, TCL_INDEX_END,
&idx2) != TCL_OK) {
return TCL_ERROR;
}
@@ -1505,12 +1505,12 @@ TclCompileLreplaceCmd(
* we must defer to direct evaluation.
*/
- if (idx1 == TCL_INDEX_AFTER) {
- suffixStart = idx1;
- } else if (idx2 == TCL_INDEX_BEFORE) {
+ if (idx1 == TCL_INDEX_NONE) {
+ suffixStart = TCL_INDEX_NONE;
+ } else if (idx2 == TCL_INDEX_NONE) {
suffixStart = idx1;
} else if (idx2 == TCL_INDEX_END) {
- suffixStart = TCL_INDEX_AFTER;
+ suffixStart = TCL_INDEX_NONE;
} else if (((idx2 < TCL_INDEX_END) && (idx1 <= TCL_INDEX_END))
|| ((idx2 >= TCL_INDEX_START) && (idx1 >= TCL_INDEX_START))) {
suffixStart = (idx1 > idx2 + 1) ? idx1 : idx2 + 1;
@@ -1570,7 +1570,7 @@ TclCompileLreplaceCmd(
TclEmitInstInt4( INST_REVERSE, 2, envPtr);
}
- if (suffixStart == TCL_INDEX_AFTER) {
+ if (suffixStart == TCL_INDEX_NONE) {
TclEmitOpcode( INST_POP, envPtr);
if (emptyPrefix) {
PushStringLiteral(envPtr, "");
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index 557340c..daab0d5 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -946,7 +946,7 @@ TclCompileStringRangeCmd(
* Parse the two indices.
*/
- if (TclGetIndexFromToken(fromTokenPtr, TCL_INDEX_START, TCL_INDEX_AFTER,
+ if (TclGetIndexFromToken(fromTokenPtr, TCL_INDEX_START, TCL_INDEX_NONE,
&idx1) != TCL_OK) {
goto nonConstantIndices;
}
@@ -955,14 +955,14 @@ TclCompileStringRangeCmd(
* the string the same as the start of the string.
*/
- if (idx1 == TCL_INDEX_AFTER) {
+ if (idx1 == TCL_INDEX_NONE) {
/* [string range $s end+1 $last] must be empty string */
OP( POP);
PUSH( "");
return TCL_OK;
}
- if (TclGetIndexFromToken(toTokenPtr, TCL_INDEX_BEFORE, TCL_INDEX_END,
+ if (TclGetIndexFromToken(toTokenPtr, TCL_INDEX_NONE, TCL_INDEX_END,
&idx2) != TCL_OK) {
goto nonConstantIndices;
}
@@ -970,7 +970,7 @@ TclCompileStringRangeCmd(
* Token parsed as an index expression. We treat all indices after
* the string the same as the end of the string.
*/
- if (idx2 == TCL_INDEX_BEFORE) {
+ if (idx2 == TCL_INDEX_NONE) {
/* [string range $s $first -1] must be empty string */
OP( POP);
PUSH( "");
@@ -1020,7 +1020,7 @@ TclCompileStringReplaceCmd(
* Check for first index known and useful at compile time.
*/
tokenPtr = TokenAfter(valueTokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_AFTER,
+ if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_START, TCL_INDEX_NONE,
&first) != TCL_OK) {
goto genericReplace;
}
@@ -1029,7 +1029,7 @@ TclCompileStringReplaceCmd(
* Check for last index known and useful at compile time.
*/
tokenPtr = TokenAfter(tokenPtr);
- if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_BEFORE, TCL_INDEX_END,
+ if (TclGetIndexFromToken(tokenPtr, TCL_INDEX_NONE, TCL_INDEX_END,
&last) != TCL_OK) {
goto genericReplace;
}
@@ -1048,8 +1048,8 @@ TclCompileStringReplaceCmd(
* compile direct to bytecode implementing the no-op.
*/
- if ((last == TCL_INDEX_BEFORE) /* Know (last < 0) */
- || (first == TCL_INDEX_AFTER) /* Know (first > end) */
+ if ((last == TCL_INDEX_NONE) /* Know (last < 0) */
+ || (first == TCL_INDEX_NONE) /* Know (first > end) */
/*
* Tricky to determine when runtime (last < first) can be
@@ -1057,20 +1057,17 @@ TclCompileStringReplaceCmd(
* cases...
*
* (first <= TCL_INDEX_END) &&
- * (last == TCL_INDEX_AFTER) => cannot tell REJECT
* (last <= TCL_INDEX END) && (last < first) => ACCEPT
* else => cannot tell REJECT
*/
|| ((first <= TCL_INDEX_END) && (last <= TCL_INDEX_END)
&& (last < first)) /* Know (last < first) */
/*
- * (first == TCL_INDEX_BEFORE) &&
- * (last == TCL_INDEX_AFTER) => (first < last) REJECT
+ * (first == TCL_INDEX_NONE) &&
* (last <= TCL_INDEX_END) => cannot tell REJECT
* else => (first < last) REJECT
*
* else [[first >= TCL_INDEX_START]] &&
- * (last == TCL_INDEX_AFTER) => cannot tell REJECT
* (last <= TCL_INDEX_END) => cannot tell REJECT
* else [[last >= TCL_INDEX START]] && (last < first) => ACCEPT
*/
@@ -1103,26 +1100,26 @@ TclCompileStringReplaceCmd(
* (first <= end)
*
* The encoded indices (first <= TCL_INDEX END) and
- * (first == TCL_INDEX_BEFORE) always meets this condition, but
+ * (first == TCL_INDEX_NONE) always meets this condition, but
* any other encoded first index has some list for which it fails.
*
* We also need, second:
*
* (last >= 0)
*
- * The encoded indices (last >= TCL_INDEX_START) and
- * (last == TCL_INDEX_AFTER) always meet this condition but any
- * other encoded last index has some list for which it fails.
+ * The encoded index (last >= TCL_INDEX_START) always meet this
+ * condition but any other encoded last index has some list for
+ * which it fails.
*
* Finally we need, third:
*
* (first <= last)
*
* Considered in combination with the constraints we already have,
- * we see that we can proceed when (first == TCL_INDEX_BEFORE)
- * or (last == TCL_INDEX_AFTER). These also permit simplification
- * of the prefix|replace|suffix construction. The other constraints,
- * though, interfere with getting a guarantee that first <= last.
+ * we see that we can proceed when (first == TCL_INDEX_NONE).
+ * These also permit simplification of the prefix|replace|suffix
+ * construction. The other constraints, though, interfere with
+ * getting a guarantee that first <= last.
*/
if ((first == TCL_INDEX_START) && (last >= TCL_INDEX_START)) {
@@ -1130,7 +1127,7 @@ TclCompileStringReplaceCmd(
tokenPtr = TokenAfter(tokenPtr);
CompileWord(envPtr, tokenPtr, interp, 4);
OP4( REVERSE, 2);
- if (last == TCL_INDEX_AFTER) {
+ if (last == INT_MAX) {
OP( POP); /* Pop original */
} else {
OP44( STR_RANGE_IMM, last + 1, TCL_INDEX_END);
@@ -1139,7 +1136,7 @@ TclCompileStringReplaceCmd(
return TCL_OK;
}
- if ((last == TCL_INDEX_AFTER) && (first <= TCL_INDEX_END)) {
+ if ((last == TCL_INDEX_NONE) && (first <= TCL_INDEX_END)) {
OP44( STR_RANGE_IMM, 0, first-1);
tokenPtr = TokenAfter(tokenPtr);
CompileWord(envPtr, tokenPtr, interp, 4);
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 04c7ee2..a0fe35c 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -4973,16 +4973,7 @@ TEBCresume(
/* Decode index value operands. */
- /*
- assert ( toIdx != TCL_INDEX_AFTER);
- *
- * Extra safety for legacy bytecodes:
- */
- if (toIdx == TCL_INDEX_AFTER) {
- toIdx = TCL_INDEX_END;
- }
-
- if ((toIdx == TCL_INDEX_BEFORE) || (fromIdx == TCL_INDEX_AFTER)) {
+ if (toIdx == TCL_INDEX_NONE) {
emptyList:
objResultPtr = Tcl_NewObj();
TRACE_APPEND(("\"%.30s\"", O2S(objResultPtr)));
@@ -4997,11 +4988,11 @@ TEBCresume(
assert ( toIdx >= 0 && toIdx < objc);
/*
- assert ( fromIdx != TCL_INDEX_BEFORE );
+ assert ( fromIdx != TCL_INDEX_NONE );
*
* Extra safety for legacy bytecodes:
*/
- if (fromIdx == TCL_INDEX_BEFORE) {
+ if (fromIdx == TCL_INDEX_NONE) {
fromIdx = TCL_INDEX_START;
}
@@ -5288,17 +5279,13 @@ TEBCresume(
/* Decode index operands. */
/*
- assert ( toIdx != TCL_INDEX_BEFORE );
- assert ( toIdx != TCL_INDEX_AFTER);
+ assert ( toIdx != TCL_INDEX_NONE );
*
* Extra safety for legacy bytecodes:
*/
- if (toIdx == TCL_INDEX_BEFORE) {
+ if (toIdx == TCL_INDEX_NONE) {
goto emptyRange;
}
- if (toIdx == TCL_INDEX_AFTER) {
- toIdx = TCL_INDEX_END;
- }
toIdx = TclIndexDecode(toIdx, length - 1);
if (toIdx < 0) {
@@ -5310,17 +5297,13 @@ TEBCresume(
assert ( toIdx >= 0 && toIdx < length );
/*
- assert ( fromIdx != TCL_INDEX_BEFORE );
- assert ( fromIdx != TCL_INDEX_AFTER);
+ assert ( fromIdx != TCL_INDEX_NONE );
*
* Extra safety for legacy bytecodes:
*/
- if (fromIdx == TCL_INDEX_BEFORE) {
+ if (fromIdx == TCL_INDEX_NONE) {
fromIdx = TCL_INDEX_START;
}
- if (fromIdx == TCL_INDEX_AFTER) {
- goto emptyRange;
- }
fromIdx = TclIndexDecode(fromIdx, length - 1);
if (fromIdx < 0) {
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 1782215..53fb629 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2512,7 +2512,7 @@ typedef struct List {
: Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
#define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
(((objPtr)->typePtr == &tclIntType \
- && (objPtr)->internalRep.wideValue >= INT_MIN \
+ && (objPtr)->internalRep.wideValue >= -1 \
&& (objPtr)->internalRep.wideValue <= INT_MAX) \
? ((*(idxPtr) = (int)(objPtr)->internalRep.wideValue), TCL_OK) \
: TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
@@ -4175,9 +4175,8 @@ MODULE_SCOPE int TclIndexDecode(int encoded, int endValue);
/* Constants used in index value encoding routines. */
#define TCL_INDEX_END (-2)
-#define TCL_INDEX_BEFORE (-1)
+#define TCL_INDEX_NONE (-1) /* Index out of range or END+1 */
#define TCL_INDEX_START (0)
-#define TCL_INDEX_AFTER (INT_MAX)
/*
*----------------------------------------------------------------
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 4c16c1f..a2670d5 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -109,10 +109,10 @@ static void ClearHash(Tcl_HashTable *tablePtr);
static void FreeProcessGlobalValue(ClientData clientData);
static void FreeThreadHash(ClientData clientData);
static int GetEndOffsetFromObj(Tcl_Obj *objPtr,
- Tcl_WideInt endValue, Tcl_WideInt *indexPtr);
+ size_t endValue, Tcl_WideInt *indexPtr);
static Tcl_HashTable * GetThreadHash(Tcl_ThreadDataKey *keyPtr);
static int GetWideForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr,
- Tcl_WideInt endValue, Tcl_WideInt *widePtr);
+ size_t endValue, Tcl_WideInt *widePtr);
static int FindElement(Tcl_Interp *interp, const char *string,
int stringLength, const char *typeStr,
const char *typeCode, const char **elementPtr,
@@ -3702,9 +3702,9 @@ GetWideForIndex(
* NULL, then no error message is left after
* errors. */
Tcl_Obj *objPtr, /* Points to the value to be parsed */
- Tcl_WideInt endValue, /* The value to be stored at *widePtr if
+ size_t endValue, /* The value to be stored at *widePtr if
* objPtr holds "end".
- * NOTE: this value may be negative. */
+ * NOTE: this value may be TCL_INDEX_NONE. */
Tcl_WideInt *widePtr) /* Location filled in with a wide integer
* representing an index. */
{
@@ -3716,7 +3716,7 @@ GetWideForIndex(
if (code == TCL_OK) {
if (numType == TCL_NUMBER_INT) {
/* objPtr holds an integer in the signed wide range */
- *widePtr = (Tcl_WideInt)(*(Tcl_WideInt *)cd);
+ *widePtr = *(Tcl_WideInt *)cd;
return TCL_OK;
}
if (numType == TCL_NUMBER_BIG) {
@@ -3838,7 +3838,7 @@ GetWideForIndex(
if (numType == TCL_NUMBER_INT) {
/* sum holds an integer in the signed wide range */
- *widePtr = (Tcl_WideInt)(*(Tcl_WideInt *)cd);
+ *widePtr = *(Tcl_WideInt *)cd;
} else {
/* sum holds an integer outside the signed wide range */
/* Truncate to the signed wide range. */
@@ -3911,8 +3911,8 @@ TclGetIntForIndex(
if (GetWideForIndex(interp, objPtr, endValue, &wide) == TCL_ERROR) {
return TCL_ERROR;
}
- if (wide < INT_MIN) {
- *indexPtr = INT_MIN;
+ if (wide < 0) {
+ *indexPtr = -1;
} else if (wide > INT_MAX) {
*indexPtr = INT_MAX;
} else {
@@ -3940,7 +3940,7 @@ TclGetIntForIndex(
static int
GetEndOffsetFromObj(
Tcl_Obj *objPtr, /* Pointer to the object to parse */
- Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if
+ size_t endValue, /* The value to be stored at "indexPtr" if
* "objPtr" holds "end". */
Tcl_WideInt *widePtr) /* Location filled in with an integer
* representing an index. */
@@ -4010,21 +4010,15 @@ GetEndOffsetFromObj(
offset = irPtr->wideValue;
- if ((endValue ^ offset) < 0) {
+ if (endValue == (size_t)-1) {
+ *widePtr = offset - 1;
+ } else if (offset < 0) {
/* Different signs, sum cannot overflow */
*widePtr = endValue + offset;
- } else if (endValue >= 0) {
- if (endValue < WIDE_MAX - offset) {
- *widePtr = endValue + offset;
- } else {
- *widePtr = WIDE_MAX;
- }
+ } else if (endValue < (Tcl_WideUInt)WIDE_MAX - offset) {
+ *widePtr = endValue + offset;
} else {
- if (endValue > WIDE_MIN - offset) {
- *widePtr = endValue + offset;
- } else {
- *widePtr = WIDE_MIN;
- }
+ *widePtr = WIDE_MAX;
}
return TCL_OK;
}
@@ -4041,7 +4035,7 @@ GetEndOffsetFromObj(
* arithmetic expressions. The absolute index values that can be
* directly meaningful as an index into either a list or a string are
* those integer values >= TCL_INDEX_START (0)
- * and < TCL_INDEX_AFTER (INT_MAX).
+ * and < INT_MAX.
* The largest string supported in Tcl 8 has bytelength INT_MAX.
* This means the largest supported character length is also INT_MAX,
* and the index of the last character in a string of length INT_MAX
@@ -4050,9 +4044,9 @@ GetEndOffsetFromObj(
* Any absolute index value parsed outside that range is encoded
* using the before and after values passed in by the
* caller as the encoding to use for indices that are either
- * less than or greater than the usable index range. TCL_INDEX_AFTER
+ * less than or greater than the usable index range. TCL_INDEX_NONE
* is available as a good choice for most callers to use for
- * after. Likewise, the value TCL_INDEX_BEFORE is good for
+ * after. Likewise, the value TCL_INDEX_NONE is good for
* most callers to use for before. Other values are possible
* when the caller knows it is helpful in producing its own behavior
* for indices before and after the indexed item.