From 449998d3589b262b87b42a2ad586dd3c70b4b9e2 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 19 Mar 2023 13:23:03 +0000 Subject: Proposed fix for [5ae5ffc3f4]: Problem with -failindex on 32-bit platform. This also fixes a memory-leak. --- generic/tclCmdAH.c | 17 +++++++++++------ generic/tclInt.h | 9 ++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 7fab2f0..dff231d 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -13,6 +13,7 @@ #include "tclInt.h" #include "tclIO.h" +#include "tclTomMath.h" #ifdef _WIN32 # include "tclWinInt.h" #endif @@ -580,13 +581,15 @@ EncodingConvertfromObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DecrRefCount(failIndex); + Tcl_DStringFree(&ds); return TCL_ERROR; } } @@ -676,13 +679,15 @@ EncodingConverttoObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DecrRefCount(failIndex); + Tcl_DStringFree(&ds); return TCL_ERROR; } } diff --git a/generic/tclInt.h b/generic/tclInt.h index a90ac79..aa9247f 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4912,7 +4912,14 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit; } while (0) #define TclNewIndexObj(objPtr, w) \ - (objPtr) = (((Tcl_WideUInt)w) >= TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideIntObj(w) + do { + Tcl_WideUInt _uw = (Tcl_WideUInt)w; + if (_uw >= TCL_INDEX_NONE) { + TclNewIntObj(objPtr, -1); + } else { + TclNewUIntObj(objPtr, w); + } + } while (0) #define TclNewDoubleObj(objPtr, d) \ (objPtr) = Tcl_NewDoubleObj(d) -- cgit v0.12 From 78c295898e25376830b59e74621cbcf9f118c495 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 19 Mar 2023 13:32:46 +0000 Subject: Doesn't look like a mem-leak: It appears that Tcl_ObjSetVar2() already handles that. --- generic/tclCmdAH.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index dff231d..5dbadb8 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -588,7 +588,6 @@ EncodingConvertfromObjCmd( NULL, failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DecrRefCount(failIndex); Tcl_DStringFree(&ds); return TCL_ERROR; } @@ -686,7 +685,6 @@ EncodingConverttoObjCmd( NULL, failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DecrRefCount(failIndex); Tcl_DStringFree(&ds); return TCL_ERROR; } -- cgit v0.12 From 1876fe215dfd8f18fcacb7967ede6fe9221bdf29 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 19 Mar 2023 13:34:04 +0000 Subject: Another fix: don't access (w) twice --- generic/tclInt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclInt.h b/generic/tclInt.h index aa9247f..6aa05a8 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4917,7 +4917,7 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit; if (_uw >= TCL_INDEX_NONE) { TclNewIntObj(objPtr, -1); } else { - TclNewUIntObj(objPtr, w); + TclNewUIntObj(objPtr, _uw); } } while (0) -- cgit v0.12 From b273a9c1d4c036fce56101f8723037d491d6618f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 20 Mar 2023 11:40:25 +0000 Subject: Use TclNewIndexObj() in stead of Tcl_NewWideIntObj(), which - actually - does the same but better for debugging. --- generic/tclCmdAH.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index ff0d00f..6c46c8e 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -720,13 +720,14 @@ EncodingConvertfromObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DStringFree(&ds); return TCL_ERROR; } } @@ -816,13 +817,14 @@ EncodingConverttoObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DStringFree(&ds); return TCL_ERROR; } } @@ -2952,7 +2954,7 @@ EachloopCmd( result = TCL_ERROR; goto done; } - /* Don't compute values here, wait until the last momement */ + /* Don't compute values here, wait until the last moment */ statePtr->argcList[i] = TclArithSeriesObjLength(statePtr->aCopyList[i]); } else { /* List values */ -- cgit v0.12