summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-18 22:44:43 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-18 22:44:43 (GMT)
commit5a02d5db9cec007d16a60b24bd8cd0b1912d123f (patch)
treef9868ebc5760bacfff4a34e36a004b12f2c8383d /generic
parent3097e10be1fdd2dac0d1865cf86b453e35fcc0f1 (diff)
parent3dd30ce854309c3433f211cacf5c430b9e8d0005 (diff)
downloadtcl-5a02d5db9cec007d16a60b24bd8cd0b1912d123f.zip
tcl-5a02d5db9cec007d16a60b24bd8cd0b1912d123f.tar.gz
tcl-5a02d5db9cec007d16a60b24bd8cd0b1912d123f.tar.bz2
Merge 8.7
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCmdIL.c17
-rw-r--r--generic/tclInt.h12
-rw-r--r--generic/tclUtil.c11
3 files changed, 25 insertions, 15 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 7faa239..0685002 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -3682,7 +3682,7 @@ Tcl_LsearchObjCmd(
itemPtr = Tcl_NewWideIntObj(i+groupOffset);
for (j=0 ; j<sortInfo.indexc ; j++) {
- Tcl_ListObjAppendElement(interp, itemPtr, Tcl_NewWideIntObj(
+ Tcl_ListObjAppendElement(interp, itemPtr, TclNewWideIntObjFromSize(
TclIndexDecode(sortInfo.indexv[j], listc)));
}
Tcl_ListObjAppendElement(interp, listPtr, itemPtr);
@@ -3704,7 +3704,7 @@ Tcl_LsearchObjCmd(
itemPtr = Tcl_NewWideIntObj(index+groupOffset);
for (j=0 ; j<sortInfo.indexc ; j++) {
- Tcl_ListObjAppendElement(interp, itemPtr, Tcl_NewWideIntObj(
+ Tcl_ListObjAppendElement(interp, itemPtr, TclNewWideIntObjFromSize(
TclIndexDecode(sortInfo.indexv[j], listc)));
}
Tcl_SetObjResult(interp, itemPtr);
@@ -4722,9 +4722,16 @@ SelectObjFromSublist(
return NULL;
}
if (currentObj == NULL) {
- Tcl_SetObjResult(infoPtr->interp, Tcl_ObjPrintf(
- "element %d missing from sublist \"%s\"",
- index, TclGetString(objPtr)));
+ if (index == TCL_INDEX_NONE) {
+ index = TCL_INDEX_END - infoPtr->indexv[i];
+ Tcl_SetObjResult(infoPtr->interp, Tcl_ObjPrintf(
+ "element end-%d missing from sublist \"%s\"",
+ index, TclGetString(objPtr)));
+ } else {
+ Tcl_SetObjResult(infoPtr->interp, Tcl_ObjPrintf(
+ "element %d missing from sublist \"%s\"",
+ index, TclGetString(objPtr)));
+ }
Tcl_SetErrorCode(infoPtr->interp, "TCL", "OPERATION", "LSORT",
"INDEXFAILED", NULL);
infoPtr->resultCode = TCL_ERROR;
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 39d40f1..c0a4ca4 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2434,7 +2434,7 @@ typedef struct List {
#define TclGetLongFromObj(interp, objPtr, longPtr) \
(((objPtr)->typePtr == &tclIntType \
&& (objPtr)->internalRep.wideValue >= (Tcl_WideInt)(LONG_MIN) \
- && (objPtr)->internalRep.wideValue <= (Tcl_WideInt)(LONG_MAX)) \
+ && (objPtr)->internalRep.wideValue <= (Tcl_WideInt)(LONG_MAX)) \
? ((*(longPtr) = (long)(objPtr)->internalRep.wideValue), TCL_OK) \
: Tcl_GetLongFromObj((interp), (objPtr), (longPtr)))
#endif
@@ -2442,14 +2442,14 @@ typedef struct List {
#define TclGetIntFromObj(interp, objPtr, intPtr) \
(((objPtr)->typePtr == &tclIntType \
&& (objPtr)->internalRep.wideValue >= (Tcl_WideInt)(INT_MIN) \
- && (objPtr)->internalRep.wideValue <= (Tcl_WideInt)(INT_MAX)) \
+ && (objPtr)->internalRep.wideValue <= (Tcl_WideInt)(INT_MAX)) \
? ((*(intPtr) = (int)(objPtr)->internalRep.wideValue), TCL_OK) \
: Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
#define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
(((objPtr)->typePtr == &tclIntType \
- && (objPtr)->internalRep.wideValue >= -1 \
- && (objPtr)->internalRep.wideValue <= INT_MAX) \
- ? ((*(idxPtr) = (int)(objPtr)->internalRep.wideValue), TCL_OK) \
+ && (objPtr)->internalRep.wideValue <= (Tcl_WideInt)(INT_MAX)) \
+ ? ((*(idxPtr) = ((objPtr)->internalRep.wideValue >= 0) \
+ ? (int)(objPtr)->internalRep.wideValue : -1), TCL_OK) \
: TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
/*
@@ -4095,7 +4095,7 @@ MODULE_SCOPE Tcl_Obj * TclGetArrayDefault(Var *arrayPtr);
MODULE_SCOPE int TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr,
size_t before, size_t after, int *indexPtr);
-MODULE_SCOPE int TclIndexDecode(int encoded, size_t endValue);
+MODULE_SCOPE size_t TclIndexDecode(int encoded, size_t endValue);
/* Constants used in index value encoding routines. */
#define TCL_INDEX_END (-2)
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 8e2d4ba..44ecd90 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3888,15 +3888,18 @@ TclIndexEncode(
*----------------------------------------------------------------------
*/
-int
+size_t
TclIndexDecode(
int encoded, /* Value to decode */
size_t endValue) /* Meaning of "end" to use, > TCL_INDEX_END */
{
- if (encoded <= TCL_INDEX_END) {
- return (encoded - TCL_INDEX_END) + endValue;
+ if (encoded > TCL_INDEX_END) {
+ return encoded;
+ }
+ if (endValue >= TCL_INDEX_END - (size_t)encoded) {
+ return endValue + encoded - TCL_INDEX_END;
}
- return encoded;
+ return TCL_INDEX_NONE;
}
/*