summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorgriffin <briang42@easystreet.net>2022-10-04 20:15:38 (GMT)
committergriffin <briang42@easystreet.net>2022-10-04 20:15:38 (GMT)
commit00199ad335823ec6b18983d1188f70b0b065b25e (patch)
tree653e3e736d41b37f57243571ac31611295b8b4bf /generic
parentf852823f2d4d5f92dee67e03cbdc4da22d8be30b (diff)
downloadtcl-00199ad335823ec6b18983d1188f70b0b065b25e.zip
tcl-00199ad335823ec6b18983d1188f70b0b065b25e.tar.gz
tcl-00199ad335823ec6b18983d1188f70b0b065b25e.tar.bz2
Fix some bugs in lseq
Diffstat (limited to 'generic')
-rwxr-xr-xgeneric/tclArithSeries.c9
-rw-r--r--generic/tclCmdAH.c17
-rw-r--r--generic/tclExecute.c7
-rw-r--r--generic/tclListObj.c8
4 files changed, 22 insertions, 19 deletions
diff --git a/generic/tclArithSeries.c b/generic/tclArithSeries.c
index ee201fa..6a02caa 100755
--- a/generic/tclArithSeries.c
+++ b/generic/tclArithSeries.c
@@ -392,7 +392,6 @@ TclArithSeriesObjStep(
} else {
*stepObj = Tcl_NewWideIntObj(arithSeriesRepPtr->step);
}
- Tcl_IncrRefCount(*stepObj);
return TCL_OK;
}
@@ -437,7 +436,6 @@ TclArithSeriesObjIndex(Tcl_Obj *arithSeriesPtr, Tcl_WideInt index, Tcl_Obj **ele
} else {
*elementObj = Tcl_NewWideIntObj(ArithSeriesIndexM(arithSeriesRepPtr, index));
}
- Tcl_IncrRefCount(*elementObj);
return TCL_OK;
}
@@ -724,8 +722,11 @@ TclArithSeriesObjRange(
}
TclArithSeriesObjIndex(arithSeriesPtr, fromIdx, &startObj);
+ Tcl_IncrRefCount(startObj);
TclArithSeriesObjIndex(arithSeriesPtr, toIdx, &endObj);
+ Tcl_IncrRefCount(endObj);
TclArithSeriesObjStep(arithSeriesPtr, &stepObj);
+ Tcl_IncrRefCount(stepObj);
if (Tcl_IsShared(arithSeriesPtr) ||
((arithSeriesPtr->refCount > 1))) {
@@ -856,6 +857,7 @@ TclArithSeriesGetElements(
}
return TCL_ERROR;
}
+ Tcl_IncrRefCount(objv[i]);
}
}
} else {
@@ -912,8 +914,11 @@ TclArithSeriesObjReverse(
len = arithSeriesRepPtr->len;
TclArithSeriesObjIndex(arithSeriesPtr, (len-1), &startObj);
+ Tcl_IncrRefCount(startObj);
TclArithSeriesObjIndex(arithSeriesPtr, 0, &endObj);
+ Tcl_IncrRefCount(endObj);
TclArithSeriesObjStep(arithSeriesPtr, &stepObj);
+ Tcl_IncrRefCount(stepObj);
if (isDouble) {
Tcl_GetDoubleFromObj(NULL, startObj, &dstart);
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 3048e82..a5c5330 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -2866,13 +2866,13 @@ EachloopCmd(
/* Values */
if (TclHasInternalRep(objv[2+i*2],&tclArithSeriesType)) {
/* Special case for Arith Series */
- statePtr->vCopyList[i] = TclArithSeriesObjCopy(interp, objv[2+i*2]);
- if (statePtr->vCopyList[i] == NULL) {
+ statePtr->aCopyList[i] = TclArithSeriesObjCopy(interp, objv[2+i*2]);
+ if (statePtr->aCopyList[i] == NULL) {
result = TCL_ERROR;
goto done;
}
/* Don't compute values here, wait until the last momement */
- statePtr->argcList[i] = TclArithSeriesObjLength(statePtr->vCopyList[i]);
+ statePtr->argcList[i] = TclArithSeriesObjLength(statePtr->aCopyList[i]);
} else {
/* List values */
statePtr->aCopyList[i] = TclListObjCopy(interp, objv[2+i*2]);
@@ -3005,12 +3005,12 @@ ForeachAssignments(
Tcl_Obj *valuePtr, *varValuePtr;
for (i=0 ; i<statePtr->numLists ; i++) {
- int isarithseries = TclHasInternalRep(statePtr->vCopyList[i],&tclArithSeriesType);
+ int isarithseries = TclHasInternalRep(statePtr->aCopyList[i],&tclArithSeriesType);
for (v=0 ; v<statePtr->varcList[i] ; v++) {
k = statePtr->index[i]++;
if (k < statePtr->argcList[i]) {
if (isarithseries) {
- if (TclArithSeriesObjIndex(statePtr->vCopyList[i], k, &valuePtr) != TCL_OK) {
+ if (TclArithSeriesObjIndex(statePtr->aCopyList[i], k, &valuePtr) != TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (setting %s loop variable \"%s\")",
(statePtr->resultList != NULL ? "lmap" : "foreach"),
@@ -3027,13 +3027,6 @@ ForeachAssignments(
varValuePtr = Tcl_ObjSetVar2(interp, statePtr->varvList[i][v],
NULL, valuePtr, TCL_LEAVE_ERR_MSG);
- if (isarithseries) {
- /* arith values have implicit reference
- ** Make sure value is cleaned up when var goes away
- */
- Tcl_DecrRefCount(valuePtr);
- }
-
if (varValuePtr == NULL) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (setting %s loop variable \"%s\")",
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index fa0dfa2..7c7bbfd 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -4883,6 +4883,7 @@ TEBCresume(
TRACE_ERROR(interp);
goto gotError;
}
+ Tcl_IncrRefCount(objResultPtr); // reference held here
goto lindexDone;
}
@@ -5187,7 +5188,11 @@ TEBCresume(
*/
do {
- Tcl_ListObjIndex(NULL, value2Ptr, i, &o);
+ if (isArithSeries) {
+ TclArithSeriesObjIndex(value2Ptr, i, &o);
+ } else {
+ Tcl_ListObjIndex(NULL, value2Ptr, i, &o);
+ }
if (o != NULL) {
s2 = TclGetStringFromObj(o, &s2len);
} else {
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 598ff6f..62bc162 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -1369,6 +1369,9 @@ TclListObjCopy(
Tcl_Obj *copyObj;
if (!TclHasInternalRep(listObj, &tclListType)) {
+ if (TclHasInternalRep(listObj,&tclArithSeriesType)) {
+ return TclArithSeriesObjCopy(interp, listObj);
+ }
if (SetListFromAny(interp, listObj) != TCL_OK) {
return NULL;
}
@@ -1943,10 +1946,6 @@ Tcl_ListObjIndex(
Tcl_Obj **elemObjs;
ListSizeT numElems;
- if (TclHasInternalRep(listObj,&tclArithSeriesType)) {
- return TclArithSeriesObjIndex(listObj, index, objPtrPtr);
- }
-
/*
* TODO
* Unlike the original list code, this does not optimize for lindex'ing
@@ -2642,6 +2641,7 @@ TclLindexFlat(
if (i==0) {
TclArithSeriesObjIndex(listObj, index, &elemObj);
} else if (index > 0) {
+ /* ArithSeries cannot be a list of lists */
Tcl_DecrRefCount(elemObj);
TclNewObj(elemObj);
Tcl_IncrRefCount(elemObj);