Skip to content

Commit

Permalink
New macro TclNewIndexObj(). For Tcl 8.7 it's the same as TclNewIntObj…
Browse files Browse the repository at this point in the history
…(), but in Tcl 9.0 not any more.

Merge 8.6
  • Loading branch information
jan.nijtmans committed Dec 21, 2021
2 parents ead6c0d + fc5ef30 commit e3c67e0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 43 deletions.
2 changes: 2 additions & 0 deletions doc/binary.n
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ RFC 2045 calls for base64 decoders to be non-strict.
.
The \fBhex\fR binary encoding converts each byte to a pair of hexadecimal
digits that represent the byte value as a hexadecimal integer.
When encoding, lower characters are used.
When decoding, upper and lower characters are accepted.
.RS
.PP
No options are supported during encoding. During decoding, the following
Expand Down
36 changes: 18 additions & 18 deletions generic/tclCmdIL.c
Original file line number Diff line number Diff line change
Expand Up @@ -2731,8 +2731,8 @@ Tcl_LremoveObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int i, idxc;
int listLen, *idxv, prevIdx, first, num;
int i, idxc, listLen, prevIdx, first, num;
int *idxv;
Tcl_Obj *listObj;

/*
Expand Down Expand Up @@ -2960,7 +2960,8 @@ Tcl_LreplaceObjCmd(
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tcl_Obj *listPtr;
int first, last, listLen, numToDelete, result;
int first, last;
int listLen, numToDelete, result;

if (objc < 4) {
Tcl_WrongNumArgs(interp, 1, objv,
Expand Down Expand Up @@ -2991,8 +2992,7 @@ Tcl_LreplaceObjCmd(

if (first == TCL_INDEX_NONE) {
first = 0;
}
if (first > listLen) {
} else if (first > listLen) {
first = listLen;
}

Expand Down Expand Up @@ -3140,9 +3140,10 @@ Tcl_LsearchObjCmd(
Tcl_Obj *const objv[]) /* Argument values. */
{
const char *bytes, *patternBytes;
int i, match, index, result=TCL_OK, listc, length, elemLen, bisect;
int i, match, index, result=TCL_OK, listc, bisect;
int length, elemLen, start, groupSize, groupOffset, lower, upper;
int allocatedIndexVector = 0;
int dataType, isIncreasing, lower, upper, start, groupSize, groupOffset;
int dataType, isIncreasing;
Tcl_WideInt patWide, objWide;
int allMatches, inlineReturn, negatedMatch, returnSubindices, noCase;
double patDouble, objDouble;
Expand Down Expand Up @@ -3514,7 +3515,7 @@ Tcl_LsearchObjCmd(
if (allMatches || inlineReturn) {
Tcl_ResetResult(interp);
} else {
TclNewIntObj(itemPtr, TCL_INDEX_NONE);
TclNewIndexObj(itemPtr, TCL_INDEX_NONE);
Tcl_SetObjResult(interp, itemPtr);
}
goto done;
Expand Down Expand Up @@ -3645,7 +3646,7 @@ Tcl_LsearchObjCmd(
* our first match might not be the first occurrence.
* Consider: 0 0 0 1 1 1 2 2 2
*
* To maintain consistancy with standard lsearch semantics, we
* To maintain consistency with standard lsearch semantics, we
* must find the leftmost occurrence of the pattern in the
* list. Thus we don't just stop searching here. This
* variation means that a search always makes log n
Expand Down Expand Up @@ -3719,8 +3720,7 @@ Tcl_LsearchObjCmd(
if (noCase) {
match = (TclUtfCasecmp(bytes, patternBytes) == 0);
} else {
match = (memcmp(bytes, patternBytes,
(size_t) length) == 0);
match = (memcmp(bytes, patternBytes, length) == 0);
}
}
break;
Expand Down Expand Up @@ -3804,10 +3804,10 @@ Tcl_LsearchObjCmd(
} else if (returnSubindices) {
int j;

TclNewIntObj(itemPtr, i+groupOffset);
TclNewIndexObj(itemPtr, i+groupOffset);
for (j=0 ; j<sortInfo.indexc ; j++) {
Tcl_Obj *elObj;
TclNewIntObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
TclNewIndexObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
Tcl_ListObjAppendElement(interp, itemPtr, elObj);
}
Tcl_ListObjAppendElement(interp, listPtr, itemPtr);
Expand All @@ -3827,16 +3827,16 @@ Tcl_LsearchObjCmd(
if (returnSubindices) {
int j;

TclNewIntObj(itemPtr, index+groupOffset);
TclNewIndexObj(itemPtr, index+groupOffset);
for (j=0 ; j<sortInfo.indexc ; j++) {
Tcl_Obj *elObj;
TclNewIntObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
TclNewIndexObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
Tcl_ListObjAppendElement(interp, itemPtr, elObj);
}
Tcl_SetObjResult(interp, itemPtr);
} else {
Tcl_Obj *elObj;
TclNewIntObj(elObj, index);
TclNewIndexObj(elObj, index);
Tcl_SetObjResult(interp, elObj);
}
} else if (index < 0) {
Expand Down Expand Up @@ -4420,7 +4420,7 @@ Tcl_LsortObjCmd(
idx = elementPtr->payload.index;
for (j = 0; j < groupSize; j++) {
if (indices) {
TclNewIntObj(objPtr, idx + j - groupOffset);
TclNewIndexObj(objPtr, idx + j - groupOffset);
newArray[i++] = objPtr;
Tcl_IncrRefCount(objPtr);
} else {
Expand All @@ -4432,7 +4432,7 @@ Tcl_LsortObjCmd(
}
} else if (indices) {
for (i=0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
TclNewIntObj(objPtr, elementPtr->payload.index);
TclNewIndexObj(objPtr, elementPtr->payload.index);
newArray[i++] = objPtr;
Tcl_IncrRefCount(objPtr);
}
Expand Down
20 changes: 10 additions & 10 deletions generic/tclCmdMZ.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,12 @@ Tcl_RegexpObjCmd(
end--;
}
} else {
start = -1;
end = -1;
start = TCL_INDEX_NONE;
end = TCL_INDEX_NONE;
}

TclNewIntObj(objs[0], start);
TclNewIntObj(objs[1], end);
TclNewIndexObj(objs[0], start);
TclNewIndexObj(objs[1], end);

newPtr = Tcl_NewListObj(2, objs);
} else {
Expand Down Expand Up @@ -1910,7 +1910,7 @@ StringIsCmd(

str_is_done:
if ((result == 0) && (failVarObj != NULL)) {
TclNewIntObj(objPtr, failat);
TclNewIndexObj(objPtr, failat);
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, objPtr, TCL_LEAVE_ERR_MSG) == NULL) {
return TCL_ERROR;
}
Expand Down Expand Up @@ -2543,7 +2543,7 @@ StringStartCmd(
cur += 1;
}
}
TclNewIntObj(obj, cur);
TclNewIndexObj(obj, cur);
Tcl_SetObjResult(interp, obj);
return TCL_OK;
}
Expand Down Expand Up @@ -2604,7 +2604,7 @@ StringEndCmd(
} else {
cur = length;
}
TclNewIntObj(obj, cur);
TclNewIndexObj(obj, cur);
Tcl_SetObjResult(interp, obj);
return TCL_OK;
}
Expand Down Expand Up @@ -3778,10 +3778,10 @@ TclNRSwitchObjCmd(
Tcl_Obj *rangeObjAry[2];

if (info.matches[j].end > 0) {
TclNewIntObj(rangeObjAry[0], info.matches[j].start);
TclNewIntObj(rangeObjAry[1], info.matches[j].end-1);
TclNewIndexObj(rangeObjAry[0], info.matches[j].start);
TclNewIndexObj(rangeObjAry[1], info.matches[j].end-1);
} else {
TclNewIntObj(rangeObjAry[1], TCL_INDEX_NONE);
TclNewIndexObj(rangeObjAry[1], TCL_INDEX_NONE);
rangeObjAry[0] = rangeObjAry[1];
}

Expand Down
26 changes: 16 additions & 10 deletions generic/tclInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4326,7 +4326,7 @@ TclScaleTime(
/*
* Invalidate the string rep first so we can use the bytes value for our
* pointer chain, and signal an obj deletion (as opposed to shimmering) with
* 'length == -1'.
* 'length == TCL_INDEX_NONE'.
* Use empty 'if ; else' to handle use in unbraced outer if/else conditions.
*/

Expand All @@ -4338,7 +4338,7 @@ TclScaleTime(
&& ((objPtr)->bytes != &tclEmptyString)) { \
ckfree((objPtr)->bytes); \
} \
(objPtr)->length = -1; \
(objPtr)->length = TCL_INDEX_NONE; \
TclFreeObjStorage(objPtr); \
TclIncrObjsFreed(); \
} else { \
Expand All @@ -4360,7 +4360,7 @@ TclScaleTime(
*/

# define TclAllocObjStorageEx(interp, objPtr) \
(objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj))
(objPtr) = (Tcl_Obj *)ckalloc(sizeof(Tcl_Obj))

# define TclFreeObjStorageEx(interp, objPtr) \
ckfree(objPtr)
Expand Down Expand Up @@ -4510,7 +4510,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
(objPtr)->bytes = &tclEmptyString; \
(objPtr)->length = 0; \
} else { \
(objPtr)->bytes = (char *) ckalloc((len) + 1); \
(objPtr)->bytes = (char *)ckalloc((len) + 1); \
memcpy((objPtr)->bytes, (bytePtr) ? (bytePtr) : &tclEmptyString, (len)); \
(objPtr)->bytes[len] = '\0'; \
(objPtr)->length = (len); \
Expand Down Expand Up @@ -4902,6 +4902,9 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
TCL_DTRACE_OBJ_CREATE(objPtr); \
} while (0)

#define TclNewIndexObj(objPtr, w) \
TclNewIntObj(objPtr, w)

#define TclNewDoubleObj(objPtr, d) \
do { \
TclIncrObjsAllocated(); \
Expand All @@ -4927,6 +4930,9 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
#define TclNewIntObj(objPtr, w) \
(objPtr) = Tcl_NewWideIntObj(w)

#define TclNewIndexObj(objPtr, w) \
TclNewIntObj(objPtr, w)

#define TclNewDoubleObj(objPtr, d) \
(objPtr) = Tcl_NewDoubleObj(d)

Expand All @@ -4939,7 +4945,7 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
* sizeof(sLiteral "") will fail to compile otherwise.
*/
#define TclNewLiteralStringObj(objPtr, sLiteral) \
TclNewStringObj((objPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
TclNewStringObj((objPtr), (sLiteral), sizeof(sLiteral "") - 1)

/*
*----------------------------------------------------------------
Expand All @@ -4952,7 +4958,7 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
*/

#define TclDStringAppendLiteral(dsPtr, sLiteral) \
Tcl_DStringAppend((dsPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
Tcl_DStringAppend((dsPtr), (sLiteral), sizeof(sLiteral "") - 1)
#define TclDStringClear(dsPtr) \
Tcl_DStringSetLength((dsPtr), 0)

Expand Down Expand Up @@ -5093,12 +5099,12 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj)); \
TclIncrObjsAllocated(); \
TclAllocObjStorageEx((interp), (_objPtr)); \
*(void **)&memPtr = (void *) (_objPtr); \
*(void **)&(memPtr) = (void *) (_objPtr); \
} while (0)

#define TclSmallFreeEx(interp, memPtr) \
do { \
TclFreeObjStorageEx((interp), (Tcl_Obj *) (memPtr)); \
TclFreeObjStorageEx((interp), (Tcl_Obj *)(memPtr)); \
TclIncrObjsFreed(); \
} while (0)

Expand All @@ -5108,12 +5114,12 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
Tcl_Obj *_objPtr; \
TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj)); \
TclNewObj(_objPtr); \
*(void **)&memPtr = (void *) _objPtr; \
*(void **)&(memPtr) = (void *)_objPtr; \
} while (0)

#define TclSmallFreeEx(interp, memPtr) \
do { \
Tcl_Obj *_objPtr = (Tcl_Obj *) memPtr; \
Tcl_Obj *_objPtr = (Tcl_Obj *)(memPtr); \
_objPtr->bytes = NULL; \
_objPtr->typePtr = NULL; \
_objPtr->refCount = 1; \
Expand Down
2 changes: 1 addition & 1 deletion generic/tclRegexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ TclRegAbout(
*/

TclNewObj(resultObj);
TclNewIntObj(infoObj, regexpPtr->re.re_nsub);
TclNewIndexObj(infoObj, regexpPtr->re.re_nsub);
Tcl_ListObjAppendElement(NULL, resultObj, infoObj);

/*
Expand Down
4 changes: 2 additions & 2 deletions generic/tclScan.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct {
Tcl_UniChar end;
} Range;

typedef struct CharSet {
typedef struct {
int exclude; /* 1 if this is an exclusion set. */
int nchars;
Tcl_UniChar *chars;
Expand Down Expand Up @@ -1089,7 +1089,7 @@ Tcl_ScanObjCmd(
if (code == TCL_OK) {
if (underflow && (nconversions == 0)) {
if (numVars) {
TclNewIntObj(objPtr, TCL_INDEX_NONE);
TclNewIndexObj(objPtr, TCL_INDEX_NONE);
} else {
if (objPtr) {
Tcl_SetListObj(objPtr, 0, NULL);
Expand Down
4 changes: 2 additions & 2 deletions generic/tclStringObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -3688,7 +3688,7 @@ TclStringFirst(
}
}
firstEnd:
TclNewIntObj(result, value);
TclNewIndexObj(result, value);
return result;
}

Expand Down Expand Up @@ -3775,7 +3775,7 @@ TclStringLast(
checkStr--;
}
lastEnd:
TclNewIntObj(result, value);
TclNewIndexObj(result, value);
return result;
}

Expand Down

0 comments on commit e3c67e0

Please sign in to comment.