Skip to content

Commit

Permalink
Merge 8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Jul 13, 2023
2 parents 6bcf9e5 + 55d0859 commit ffee5d0
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions generic/tclListObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
/*
* Prototypes for non-inline static functions defined later in this file:
*/
static int MemoryAllocationError(Tcl_Interp *, Tcl_Size size);
static int MemoryAllocationError(Tcl_Interp *, size_t size);
static int ListLimitExceededError(Tcl_Interp *);
static ListStore *ListStoreNew(Tcl_Size objc, Tcl_Obj *const objv[], int flags);
static int ListRepInit(Tcl_Size objc, Tcl_Obj *const objv[], int flags, ListRep *);
Expand Down Expand Up @@ -463,15 +463,15 @@ ObjArrayCopy(
static int
MemoryAllocationError(
Tcl_Interp *interp, /* Interpreter for error message. May be NULL */
Tcl_Size size) /* Size of attempted allocation that failed */
size_t size) /* Size of attempted allocation that failed */
{
if (interp != NULL) {
Tcl_SetObjResult(
interp,
Tcl_ObjPrintf(
"list construction failed: unable to alloc %" TCL_LL_MODIFIER
"list construction failed: unable to alloc %" TCL_Z_MODIFIER
"u bytes",
(Tcl_WideInt)size));
size));
Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
}
return TCL_ERROR;
Expand Down Expand Up @@ -642,8 +642,11 @@ ListRepValidate(const ListRep *repPtr, const char *file, int lineNum)

/* Separate each condition so line number gives exact reason for failure */
INVARIANT(storePtr != NULL);
INVARIANT(storePtr->numAllocated >= 0);
INVARIANT(storePtr->numAllocated <= LIST_MAX);
INVARIANT(storePtr->firstUsed >= 0);
INVARIANT(storePtr->firstUsed < storePtr->numAllocated);
INVARIANT(storePtr->numUsed >= 0);
INVARIANT(storePtr->numUsed <= storePtr->numAllocated);
INVARIANT(storePtr->firstUsed <= (storePtr->numAllocated - storePtr->numUsed));

Expand Down Expand Up @@ -754,9 +757,9 @@ ListStoreNew(
}
if (storePtr == NULL) {
if (flags & LISTREP_PANIC_ON_FAIL) {
Tcl_Panic("list creation failed: unable to alloc %" TCL_Z_MODIFIER
"u bytes",
LIST_SIZE(objc));
Tcl_Panic("list creation failed: unable to alloc %" TCL_SIZE_MODIFIER
"d bytes",
LIST_SIZE(objc));
}
return NULL;
}
Expand Down Expand Up @@ -833,7 +836,7 @@ ListStoreReallocate (ListStore *storePtr, Tcl_Size needed)
}
return storePtr;
}


/*
*----------------------------------------------------------------------
*
Expand Down Expand Up @@ -1083,7 +1086,7 @@ Tcl_NewListObj(

TclNewObj(listObj);

if (objc + 1 <= 1) {
if (objc <= 0) {
return listObj;
}

Expand Down Expand Up @@ -1139,7 +1142,7 @@ Tcl_DbNewListObj(

TclDbNewObj(listObj, file, line);

if (objc + 1 <= 1) {
if (objc <= 0) {
return listObj;
}

Expand Down Expand Up @@ -1301,7 +1304,7 @@ Tcl_SetListObj(
* not be called with objc == 0!
*/

if (objc + 1 > 1) {
if (objc > 0) {
ListRep listRep;
/* TODO - perhaps ask for extra space? */
ListRepInit(objc, objv, LISTREP_PANIC_ON_FAIL, &listRep);
Expand Down Expand Up @@ -1904,14 +1907,14 @@ Tcl_ListObjIndex(
{
Tcl_Obj **elemObjs;
Tcl_Size numElems;
int hasAbstractList = TclObjTypeHasProc(listObj,indexProc) != 0;

/* Empty string => empty list. Avoid unnecessary shimmering */
if (listObj->bytes == &tclEmptyString) {
*objPtrPtr = NULL;
return TCL_OK;
}

int hasAbstractList = TclObjTypeHasProc(listObj,indexProc) != 0;
if (hasAbstractList) {
return TclObjTypeIndex(interp, listObj, index, objPtrPtr);
}
Expand All @@ -1920,7 +1923,7 @@ Tcl_ListObjIndex(
!= TCL_OK) {
return TCL_ERROR;
}
if (index < 0 || index >= numElems) {
if ((index < 0) || (index >= numElems)) {
*objPtrPtr = NULL;
} else {
*objPtrPtr = elemObjs[index];
Expand Down Expand Up @@ -2748,17 +2751,16 @@ TclLsetList(
* shimmering; see TIP #22 and #23 for details.
*/

if (!TclHasInternalRep(indexArgObj, &tclListType) &&
TclGetIntForIndexM(NULL, indexArgObj, TCL_SIZE_MAX - 1, &index)
== TCL_OK) {
if (!TclHasInternalRep(indexArgObj, &tclListType)
&& TclGetIntForIndexM(NULL, indexArgObj, TCL_SIZE_MAX - 1, &index)
== TCL_OK) {

if (TclObjTypeHasProc(listObj, setElementProc)) {
indices = &indexArgObj;
retValueObj =
TclObjTypeSetElement(interp, listObj, 1, indices, valueObj);
if (retValueObj) Tcl_IncrRefCount(retValueObj);
} else {

/* indexArgPtr designates a single index. */
/* T:listrep-1.{2.1,12.1,15.1,19.1},2.{2.3,9.3,10.1,13.1,16.1}, 3.{4,5,6}.3 */
retValueObj = TclLsetFlat(interp, listObj, 1, &indexArgObj, valueObj);
Expand Down Expand Up @@ -3139,10 +3141,10 @@ TclListObjSetElement(
elemCount = ListRepLength(&listRep);

/* Ensure that the index is in bounds. */
if (index>=elemCount) {
if ((index < 0) || (index >= elemCount)) {
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"index \"%" TCL_Z_MODIFIER "u\" out of range", index));
"index \"%" TCL_SIZE_MODIFIER "u\" out of range", index));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX",
"OUTOFRANGE", NULL);
}
Expand Down

0 comments on commit ffee5d0

Please sign in to comment.