summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-16 20:15:16 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-16 20:15:16 (GMT)
commit3097e10be1fdd2dac0d1865cf86b453e35fcc0f1 (patch)
tree8d7fe534d25cccf1c3bfe30105a1b0b5cd4d5970 /generic/tclUtil.c
parent325b3d3e945fe34fd9d747370d49eebbded9b18e (diff)
parent00f134d99d29092b3e42776297c8facaa29efcab (diff)
downloadtcl-3097e10be1fdd2dac0d1865cf86b453e35fcc0f1.zip
tcl-3097e10be1fdd2dac0d1865cf86b453e35fcc0f1.tar.gz
tcl-3097e10be1fdd2dac0d1865cf86b453e35fcc0f1.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 6f2fba5..8e2d4ba 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -102,10 +102,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,
@@ -3429,9 +3429,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. */
{
@@ -3443,7 +3443,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) {
@@ -3565,7 +3565,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. */
@@ -3645,8 +3645,8 @@ TclGetIntForIndex(
&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 {
@@ -3673,11 +3673,11 @@ TclGetIntForIndex(
static int
GetEndOffsetFromObj(
- Tcl_Obj *objPtr, /* Pointer to the object to parse */
- Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if
- * "objPtr" holds "end". */
- Tcl_WideInt *widePtr) /* Location filled in with an integer
- * representing an index. */
+ Tcl_Obj *objPtr, /* Pointer to the object to parse */
+ 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. */
{
Tcl_ObjIntRep *irPtr;
Tcl_WideInt offset = 0; /* Offset in the "end-offset" expression */
@@ -3744,21 +3744,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;
}
@@ -3775,7 +3769,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
@@ -3784,9 +3778,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.