From bf8b4d6d182eb40f12e2530488f9a0a7c106525e Mon Sep 17 00:00:00 2001 From: griffin Date: Thu, 10 Aug 2023 21:12:05 +0000 Subject: Revert more bits. --- generic/tclBasic.c | 4 ---- generic/tclCmdAH.c | 8 ------- generic/tclCmdIL.c | 19 ---------------- generic/tclEnsemble.c | 24 -------------------- generic/tclEvent.c | 3 --- generic/tclExecute.c | 11 --------- generic/tclIOGT.c | 3 --- generic/tclIORChan.c | 6 ----- generic/tclListObj.c | 62 ++++++++++++++++++--------------------------------- generic/tclUtil.c | 3 --- 10 files changed, 22 insertions(+), 121 deletions(-) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index c4ba858..8b6df79 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -6154,10 +6154,6 @@ TclNREvalObjEx( Tcl_IncrRefCount(objPtr); listPtr = Tcl_DuplicateObj(objPtr); - if (!listPtr) { - Tcl_DecrRefCount(objPtr); - return TCL_ERROR; - } Tcl_IncrRefCount(listPtr); if (word != INT_MIN) { diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 9a9e433..42121f6 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -2788,10 +2788,6 @@ EachloopCmd( /* List */ /* Variables */ statePtr->vCopyList[i] = Tcl_DuplicateObj(objv[1+i*2]); - if (!statePtr->vCopyList[i]) { - result = TCL_ERROR; - goto done; - } result = TclListObjLengthM(interp, statePtr->vCopyList[i], &statePtr->varcList[i]); if (result != TCL_OK) { @@ -2823,10 +2819,6 @@ EachloopCmd( statePtr->argcList[i] = TclObjTypeLength(statePtr->aCopyList[i]); } else { statePtr->aCopyList[i] = Tcl_DuplicateObj(objv[2+i*2]); - if (!statePtr->aCopyList[i]) { - result = TCL_ERROR; - goto done; - } result = TclListObjGetElementsM(interp, statePtr->aCopyList[i], &statePtr->argcList[i], &statePtr->argvList[i]); if (result != TCL_OK) { diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 4ae7ee2..b6b4900 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2316,9 +2316,6 @@ Tcl_LassignObjCmd( } listCopyPtr = Tcl_DuplicateObj(objv[1]); - if (!listCopyPtr) { - return TCL_ERROR; - } Tcl_IncrRefCount(listCopyPtr); /* Important! fs */ code = TclListObjGetElementsM( @@ -2486,9 +2483,6 @@ Tcl_LinsertObjCmd( listPtr = objv[1]; if (Tcl_IsShared(listPtr)) { listPtr = Tcl_DuplicateObj(listPtr); - if (!listPtr) { - return TCL_ERROR; - } copied = 1; } @@ -2691,9 +2685,6 @@ Tcl_LpopObjCmd( if (objc == 2) { if (Tcl_IsShared(listPtr)) { listPtr = Tcl_DuplicateObj(listPtr); - if (!listPtr) { - return TCL_ERROR; - } copied = 1; } result = Tcl_ListObjReplace(interp, listPtr, listLen - 1, 1, 0, NULL); @@ -2884,10 +2875,6 @@ Tcl_LremoveObjCmd( if (Tcl_IsShared(listObj)) { listObj = Tcl_DuplicateObj(listObj); - if (!listObj) { - status = TCL_ERROR; - goto done; - } copied = 1; } num = 0; @@ -3140,9 +3127,6 @@ Tcl_LreplaceObjCmd( listPtr = objv[1]; if (Tcl_IsShared(listPtr)) { listPtr = Tcl_DuplicateObj(listPtr); - if (!listPtr) { - return TCL_ERROR; - } } /* @@ -5132,9 +5116,6 @@ Tcl_LeditObjCmd( if (Tcl_IsShared(listPtr)) { listPtr = Tcl_DuplicateObj(listPtr); - if (!listPtr) { - return TCL_ERROR; - } createdNewObj = 1; } else { createdNewObj = 0; diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index b6c0931..9e13c93 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -313,15 +313,6 @@ TclNamespaceEnsembleCmd( Tcl_ListObjReplace(NULL, newList, 0, 1, 1, &newCmd); if (patchedDict == NULL) { patchedDict = Tcl_DuplicateObj(objv[1]); - if (!patchedDict) { - if (allocatedMapFlag) { - Tcl_DecrRefCount(mapObj); - } - Tcl_DecrRefCount(newList); - Tcl_DecrRefCount(newCmd); - Tcl_DecrRefCount(patchedDict); - return TCL_ERROR; - } } Tcl_DictObjPut(NULL, patchedDict, subcmdWordsObj, newList); @@ -606,12 +597,6 @@ TclNamespaceEnsembleCmd( cmd = TclGetString(listv[0]); if (!(cmd[0] == ':' && cmd[1] == ':')) { Tcl_Obj *newList = Tcl_DuplicateObj(listObj); - if (!newList) { - if (patchedDict) { - Tcl_DecrRefCount(patchedDict); - } - goto freeMapAndError; - } Tcl_Obj *newCmd = NewNsObj((Tcl_Namespace*)nsPtr); if (nsPtr->parentPtr) { @@ -622,9 +607,6 @@ TclNamespaceEnsembleCmd( &newCmd); if (patchedDict == NULL) { patchedDict = Tcl_DuplicateObj(objv[1]); - if (!patchedDict) { - goto freeMapAndError; - } } Tcl_DictObjPut(NULL, patchedDict, subcmdWordsObj, newList); @@ -1923,9 +1905,6 @@ NsEnsembleImplementationCmdNR( if (objc == 2) { copyPtr = Tcl_DuplicateObj(prefixObj); - if (!copyPtr) { - return TCL_ERROR; - } } else { copyPtr = Tcl_NewListObj(objc - 2 + prefixObjc, NULL); Tcl_ListObjAppendList(NULL, copyPtr, prefixObj); @@ -2326,9 +2305,6 @@ EnsembleUnknownCallback( */ unknownCmd = Tcl_DuplicateObj(ensemblePtr->unknownHandler); - if (!unknownCmd) { - return TCL_ERROR; - } TclNewObj(ensObj); Tcl_GetCommandFullName(interp, ensemblePtr->token, ensObj); Tcl_ListObjAppendElement(NULL, unknownCmd, ensObj); diff --git a/generic/tclEvent.c b/generic/tclEvent.c index ca63fab..57287f8 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -233,9 +233,6 @@ HandleBgErrors( */ Tcl_Obj *copyObj = Tcl_DuplicateObj(assocPtr->cmdPrefix); - if (!copyObj) { - return; - } errPtr = assocPtr->firstBgPtr; diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 6387763..5588c00 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -3383,11 +3383,6 @@ TEBCresume( newValue = Tcl_DuplicateObj(objResultPtr); CACHE_STACK_INFO(); - if (!newValue) { - TRACE_ERROR(interp); - goto gotError; - } - TclDecrRefCount(objResultPtr); varPtr->value.objPtr = objResultPtr = newValue; Tcl_IncrRefCount(newValue); @@ -3448,9 +3443,6 @@ TEBCresume( DECACHE_STACK_INFO(); valueToAssign = Tcl_DuplicateObj(objResultPtr); CACHE_STACK_INFO(); - if (!valueToAssign) { - goto errorInLappendListPtr; - } createdNewObj = 1; } else { valueToAssign = objResultPtr; @@ -6485,9 +6477,6 @@ TEBCresume( DECACHE_STACK_INFO(); objPtr = Tcl_DuplicateObj(listPtr); CACHE_STACK_INFO(); - if (!objPtr) { - goto gotError; - } Tcl_IncrRefCount(objPtr); Tcl_DecrRefCount(listPtr); OBJ_AT_DEPTH(listTmpDepth) = objPtr; diff --git a/generic/tclIOGT.c b/generic/tclIOGT.c index fb80041..4497797 100644 --- a/generic/tclIOGT.c +++ b/generic/tclIOGT.c @@ -380,9 +380,6 @@ ExecuteCallback( Tcl_InterpState state = NULL; int res = TCL_OK; Tcl_Obj *command = Tcl_DuplicateObj(dataPtr->command); - if (!command) { - return TCL_ERROR; - } Tcl_Interp *eval = dataPtr->interp; Tcl_Preserve(eval); diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c index bf6be56..af61c4c 100644 --- a/generic/tclIORChan.c +++ b/generic/tclIORChan.c @@ -2262,9 +2262,6 @@ NewReflectedChannel( rcPtr->interest = 0; /* Initially no interest registered */ rcPtr->cmd = Tcl_DuplicateObj(cmdpfxObj); - if (!rcPtr->cmd) { - return NULL; - } Tcl_IncrRefCount(rcPtr->cmd); rcPtr->methods = Tcl_NewListObj(METH_WRITE + 1, NULL); while (mn <= (int)METH_WRITE) { @@ -2402,9 +2399,6 @@ InvokeTclMethod( */ cmd = Tcl_DuplicateObj(rcPtr->cmd); - if (!cmd) { - return TCL_ERROR; - } Tcl_ListObjIndex(NULL, rcPtr->methods, method, &methObj); Tcl_ListObjAppendElement(NULL, cmd, methObj); Tcl_ListObjAppendElement(NULL, cmd, rcPtr->name); diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 482f270..557be50 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -2546,26 +2546,18 @@ TclLindexList( } /* - * Make a private copy of the index list argument to keep the internal - * representation of the indices array unchanged while it is in use. This - * is probably unnecessary. It does not appear that any damaging change to - * the internal representation is possible, and no test has been devised to - * show any error when this private copy is not made, But it's cheap, and - * it offers some future-proofing insurance in case the TclLindexFlat - * implementation changes in some unexpected way, or some new form of trace - * or callback permits things to happen that the current implementation - * does not. + * Here we make a private copy of the index list argument to avoid any + * shimmering issues that might invalidate the indices array below while + * we are still using it. This is probably unnecessary. It does not appear + * that any damaging shimmering is possible, and no test has been devised + * to show any error when this private copy is not made. But it's cheap, + * and it offers some future-proofing insurance in case the TclLindexFlat + * implementation changes in some unexpected way, or some new form of + * trace or callback permits things to happen that the current + * implementation does not. */ indexListCopy = Tcl_DuplicateObj(argObj); - if (!indexListCopy) { - /* - * The argument is neither an index nor a well-formed list. - * Report the error via TclLindexFlat. - * TODO - This is as original code. why not directly return an error? - */ - return TclLindexFlat(interp, listObj, 1, &argObj); - } status = TclListObjGetElementsM( interp, indexListCopy, &numIndexObjs, &indexObjs); if (status != TCL_OK) { @@ -2847,7 +2839,7 @@ TclLsetFlat( Tcl_Obj *valueObj) /* Value arg to 'lset' or NULL to 'lpop'. */ { Tcl_Size index, len; - int copied = 0, result; + int result; Tcl_Obj *subListObj, *retValueObj; Tcl_Obj *pendingInvalidates[10]; Tcl_Obj **pendingInvalidatesPtr = pendingInvalidates; @@ -2867,14 +2859,16 @@ TclLsetFlat( } /* - * If the list is shared, make a copy to modify (copy-on-write). The string - * representation and internal representation of listObj remains unchanged. + * If the list is shared, make a copy we can modify (copy-on-write). We + * 1) we have not yet confirmed listObj is actually a list; 2) We make a + * verbatim copy of any existing string rep, and when we combine that with + * the delayed invalidation of string reps of modified Tcl_Obj's + * implemented below, the outcome is that any error condition that causes + * this routine to return NULL, will leave the string rep of listObj and + * all elements to be unchanged. */ subListObj = Tcl_IsShared(listObj) ? Tcl_DuplicateObj(listObj) : listObj; - if (!subListObj) { - return NULL; - } /* * Anchor the linked list of Tcl_Obj's whose string reps must be @@ -2947,9 +2941,10 @@ TclLsetFlat( } /* - * No error conditions. If this is not the last index, determine the - * next sublist for the next pass through the loop, and take steps to - * make sure it is unshared in order to modify it. + * No error conditions. As long as we're not yet on the last index, + * determine the next sublist for the next pass through the loop, + * and take steps to make sure it is an unshared copy, as we intend + * to modify it. */ if (--indexCount) { @@ -2961,10 +2956,6 @@ TclLsetFlat( } if (Tcl_IsShared(subListObj)) { subListObj = Tcl_DuplicateObj(subListObj); - if (!subListObj) { - return NULL; - } - copied = 1; } /* @@ -2982,16 +2973,7 @@ TclLsetFlat( TclListObjSetElement(NULL, parentList, index, subListObj); } if (Tcl_IsShared(subListObj)) { - Tcl_Obj * newSubListObj; - newSubListObj = Tcl_DuplicateObj(subListObj); - if (copied) { - Tcl_DecrRefCount(subListObj); - } - if (newSubListObj) { - subListObj = newSubListObj; - } else { - return NULL; - } + subListObj = Tcl_DuplicateObj(subListObj); TclListObjSetElement(NULL, parentList, index, subListObj); } diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 64df0e5..cf1950c 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2011,9 +2011,6 @@ Tcl_ConcatObj( Tcl_BumpObj(elemPtr); // could be an an abstract list element } else { resPtr = Tcl_DuplicateObj(objPtr); - if (!resPtr) { - return NULL; - } } } if (!resPtr) { -- cgit v0.12