Skip to content

Commit e3c67e0

Browse files
author
jan.nijtmans
committed
New macro TclNewIndexObj(). For Tcl 8.7 it's the same as TclNewIntObj(), but in Tcl 9.0 not any more.
Merge 8.6
2 parents ead6c0d + fc5ef30 commit e3c67e0

File tree

7 files changed

+51
-43
lines changed

7 files changed

+51
-43
lines changed

doc/binary.n

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ RFC 2045 calls for base64 decoders to be non-strict.
8282
.
8383
The \fBhex\fR binary encoding converts each byte to a pair of hexadecimal
8484
digits that represent the byte value as a hexadecimal integer.
85+
When encoding, lower characters are used.
86+
When decoding, upper and lower characters are accepted.
8587
.RS
8688
.PP
8789
No options are supported during encoding. During decoding, the following

generic/tclCmdIL.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -2731,8 +2731,8 @@ Tcl_LremoveObjCmd(
27312731
int objc, /* Number of arguments. */
27322732
Tcl_Obj *const objv[]) /* Argument objects. */
27332733
{
2734-
int i, idxc;
2735-
int listLen, *idxv, prevIdx, first, num;
2734+
int i, idxc, listLen, prevIdx, first, num;
2735+
int *idxv;
27362736
Tcl_Obj *listObj;
27372737

27382738
/*
@@ -2960,7 +2960,8 @@ Tcl_LreplaceObjCmd(
29602960
Tcl_Obj *const objv[]) /* Argument objects. */
29612961
{
29622962
Tcl_Obj *listPtr;
2963-
int first, last, listLen, numToDelete, result;
2963+
int first, last;
2964+
int listLen, numToDelete, result;
29642965

29652966
if (objc < 4) {
29662967
Tcl_WrongNumArgs(interp, 1, objv,
@@ -2991,8 +2992,7 @@ Tcl_LreplaceObjCmd(
29912992

29922993
if (first == TCL_INDEX_NONE) {
29932994
first = 0;
2994-
}
2995-
if (first > listLen) {
2995+
} else if (first > listLen) {
29962996
first = listLen;
29972997
}
29982998

@@ -3140,9 +3140,10 @@ Tcl_LsearchObjCmd(
31403140
Tcl_Obj *const objv[]) /* Argument values. */
31413141
{
31423142
const char *bytes, *patternBytes;
3143-
int i, match, index, result=TCL_OK, listc, length, elemLen, bisect;
3143+
int i, match, index, result=TCL_OK, listc, bisect;
3144+
int length, elemLen, start, groupSize, groupOffset, lower, upper;
31443145
int allocatedIndexVector = 0;
3145-
int dataType, isIncreasing, lower, upper, start, groupSize, groupOffset;
3146+
int dataType, isIncreasing;
31463147
Tcl_WideInt patWide, objWide;
31473148
int allMatches, inlineReturn, negatedMatch, returnSubindices, noCase;
31483149
double patDouble, objDouble;
@@ -3514,7 +3515,7 @@ Tcl_LsearchObjCmd(
35143515
if (allMatches || inlineReturn) {
35153516
Tcl_ResetResult(interp);
35163517
} else {
3517-
TclNewIntObj(itemPtr, TCL_INDEX_NONE);
3518+
TclNewIndexObj(itemPtr, TCL_INDEX_NONE);
35183519
Tcl_SetObjResult(interp, itemPtr);
35193520
}
35203521
goto done;
@@ -3645,7 +3646,7 @@ Tcl_LsearchObjCmd(
36453646
* our first match might not be the first occurrence.
36463647
* Consider: 0 0 0 1 1 1 2 2 2
36473648
*
3648-
* To maintain consistancy with standard lsearch semantics, we
3649+
* To maintain consistency with standard lsearch semantics, we
36493650
* must find the leftmost occurrence of the pattern in the
36503651
* list. Thus we don't just stop searching here. This
36513652
* variation means that a search always makes log n
@@ -3719,8 +3720,7 @@ Tcl_LsearchObjCmd(
37193720
if (noCase) {
37203721
match = (TclUtfCasecmp(bytes, patternBytes) == 0);
37213722
} else {
3722-
match = (memcmp(bytes, patternBytes,
3723-
(size_t) length) == 0);
3723+
match = (memcmp(bytes, patternBytes, length) == 0);
37243724
}
37253725
}
37263726
break;
@@ -3804,10 +3804,10 @@ Tcl_LsearchObjCmd(
38043804
} else if (returnSubindices) {
38053805
int j;
38063806

3807-
TclNewIntObj(itemPtr, i+groupOffset);
3807+
TclNewIndexObj(itemPtr, i+groupOffset);
38083808
for (j=0 ; j<sortInfo.indexc ; j++) {
38093809
Tcl_Obj *elObj;
3810-
TclNewIntObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
3810+
TclNewIndexObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
38113811
Tcl_ListObjAppendElement(interp, itemPtr, elObj);
38123812
}
38133813
Tcl_ListObjAppendElement(interp, listPtr, itemPtr);
@@ -3827,16 +3827,16 @@ Tcl_LsearchObjCmd(
38273827
if (returnSubindices) {
38283828
int j;
38293829

3830-
TclNewIntObj(itemPtr, index+groupOffset);
3830+
TclNewIndexObj(itemPtr, index+groupOffset);
38313831
for (j=0 ; j<sortInfo.indexc ; j++) {
38323832
Tcl_Obj *elObj;
3833-
TclNewIntObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
3833+
TclNewIndexObj(elObj, TclIndexDecode(sortInfo.indexv[j], listc));
38343834
Tcl_ListObjAppendElement(interp, itemPtr, elObj);
38353835
}
38363836
Tcl_SetObjResult(interp, itemPtr);
38373837
} else {
38383838
Tcl_Obj *elObj;
3839-
TclNewIntObj(elObj, index);
3839+
TclNewIndexObj(elObj, index);
38403840
Tcl_SetObjResult(interp, elObj);
38413841
}
38423842
} else if (index < 0) {
@@ -4420,7 +4420,7 @@ Tcl_LsortObjCmd(
44204420
idx = elementPtr->payload.index;
44214421
for (j = 0; j < groupSize; j++) {
44224422
if (indices) {
4423-
TclNewIntObj(objPtr, idx + j - groupOffset);
4423+
TclNewIndexObj(objPtr, idx + j - groupOffset);
44244424
newArray[i++] = objPtr;
44254425
Tcl_IncrRefCount(objPtr);
44264426
} else {
@@ -4432,7 +4432,7 @@ Tcl_LsortObjCmd(
44324432
}
44334433
} else if (indices) {
44344434
for (i=0; elementPtr != NULL ; elementPtr = elementPtr->nextPtr) {
4435-
TclNewIntObj(objPtr, elementPtr->payload.index);
4435+
TclNewIndexObj(objPtr, elementPtr->payload.index);
44364436
newArray[i++] = objPtr;
44374437
Tcl_IncrRefCount(objPtr);
44384438
}

generic/tclCmdMZ.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,12 @@ Tcl_RegexpObjCmd(
385385
end--;
386386
}
387387
} else {
388-
start = -1;
389-
end = -1;
388+
start = TCL_INDEX_NONE;
389+
end = TCL_INDEX_NONE;
390390
}
391391

392-
TclNewIntObj(objs[0], start);
393-
TclNewIntObj(objs[1], end);
392+
TclNewIndexObj(objs[0], start);
393+
TclNewIndexObj(objs[1], end);
394394

395395
newPtr = Tcl_NewListObj(2, objs);
396396
} else {
@@ -1910,7 +1910,7 @@ StringIsCmd(
19101910

19111911
str_is_done:
19121912
if ((result == 0) && (failVarObj != NULL)) {
1913-
TclNewIntObj(objPtr, failat);
1913+
TclNewIndexObj(objPtr, failat);
19141914
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, objPtr, TCL_LEAVE_ERR_MSG) == NULL) {
19151915
return TCL_ERROR;
19161916
}
@@ -2543,7 +2543,7 @@ StringStartCmd(
25432543
cur += 1;
25442544
}
25452545
}
2546-
TclNewIntObj(obj, cur);
2546+
TclNewIndexObj(obj, cur);
25472547
Tcl_SetObjResult(interp, obj);
25482548
return TCL_OK;
25492549
}
@@ -2604,7 +2604,7 @@ StringEndCmd(
26042604
} else {
26052605
cur = length;
26062606
}
2607-
TclNewIntObj(obj, cur);
2607+
TclNewIndexObj(obj, cur);
26082608
Tcl_SetObjResult(interp, obj);
26092609
return TCL_OK;
26102610
}
@@ -3778,10 +3778,10 @@ TclNRSwitchObjCmd(
37783778
Tcl_Obj *rangeObjAry[2];
37793779

37803780
if (info.matches[j].end > 0) {
3781-
TclNewIntObj(rangeObjAry[0], info.matches[j].start);
3782-
TclNewIntObj(rangeObjAry[1], info.matches[j].end-1);
3781+
TclNewIndexObj(rangeObjAry[0], info.matches[j].start);
3782+
TclNewIndexObj(rangeObjAry[1], info.matches[j].end-1);
37833783
} else {
3784-
TclNewIntObj(rangeObjAry[1], TCL_INDEX_NONE);
3784+
TclNewIndexObj(rangeObjAry[1], TCL_INDEX_NONE);
37853785
rangeObjAry[0] = rangeObjAry[1];
37863786
}
37873787

generic/tclInt.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ TclScaleTime(
43264326
/*
43274327
* Invalidate the string rep first so we can use the bytes value for our
43284328
* pointer chain, and signal an obj deletion (as opposed to shimmering) with
4329-
* 'length == -1'.
4329+
* 'length == TCL_INDEX_NONE'.
43304330
* Use empty 'if ; else' to handle use in unbraced outer if/else conditions.
43314331
*/
43324332

@@ -4338,7 +4338,7 @@ TclScaleTime(
43384338
&& ((objPtr)->bytes != &tclEmptyString)) { \
43394339
ckfree((objPtr)->bytes); \
43404340
} \
4341-
(objPtr)->length = -1; \
4341+
(objPtr)->length = TCL_INDEX_NONE; \
43424342
TclFreeObjStorage(objPtr); \
43434343
TclIncrObjsFreed(); \
43444344
} else { \
@@ -4360,7 +4360,7 @@ TclScaleTime(
43604360
*/
43614361

43624362
# define TclAllocObjStorageEx(interp, objPtr) \
4363-
(objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj))
4363+
(objPtr) = (Tcl_Obj *)ckalloc(sizeof(Tcl_Obj))
43644364

43654365
# define TclFreeObjStorageEx(interp, objPtr) \
43664366
ckfree(objPtr)
@@ -4510,7 +4510,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
45104510
(objPtr)->bytes = &tclEmptyString; \
45114511
(objPtr)->length = 0; \
45124512
} else { \
4513-
(objPtr)->bytes = (char *) ckalloc((len) + 1); \
4513+
(objPtr)->bytes = (char *)ckalloc((len) + 1); \
45144514
memcpy((objPtr)->bytes, (bytePtr) ? (bytePtr) : &tclEmptyString, (len)); \
45154515
(objPtr)->bytes[len] = '\0'; \
45164516
(objPtr)->length = (len); \
@@ -4902,6 +4902,9 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
49024902
TCL_DTRACE_OBJ_CREATE(objPtr); \
49034903
} while (0)
49044904

4905+
#define TclNewIndexObj(objPtr, w) \
4906+
TclNewIntObj(objPtr, w)
4907+
49054908
#define TclNewDoubleObj(objPtr, d) \
49064909
do { \
49074910
TclIncrObjsAllocated(); \
@@ -4927,6 +4930,9 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
49274930
#define TclNewIntObj(objPtr, w) \
49284931
(objPtr) = Tcl_NewWideIntObj(w)
49294932

4933+
#define TclNewIndexObj(objPtr, w) \
4934+
TclNewIntObj(objPtr, w)
4935+
49304936
#define TclNewDoubleObj(objPtr, d) \
49314937
(objPtr) = Tcl_NewDoubleObj(d)
49324938

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

49444950
/*
49454951
*----------------------------------------------------------------
@@ -4952,7 +4958,7 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
49524958
*/
49534959

49544960
#define TclDStringAppendLiteral(dsPtr, sLiteral) \
4955-
Tcl_DStringAppend((dsPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
4961+
Tcl_DStringAppend((dsPtr), (sLiteral), sizeof(sLiteral "") - 1)
49564962
#define TclDStringClear(dsPtr) \
49574963
Tcl_DStringSetLength((dsPtr), 0)
49584964

@@ -5093,12 +5099,12 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
50935099
TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj)); \
50945100
TclIncrObjsAllocated(); \
50955101
TclAllocObjStorageEx((interp), (_objPtr)); \
5096-
*(void **)&memPtr = (void *) (_objPtr); \
5102+
*(void **)&(memPtr) = (void *) (_objPtr); \
50975103
} while (0)
50985104

50995105
#define TclSmallFreeEx(interp, memPtr) \
51005106
do { \
5101-
TclFreeObjStorageEx((interp), (Tcl_Obj *) (memPtr)); \
5107+
TclFreeObjStorageEx((interp), (Tcl_Obj *)(memPtr)); \
51025108
TclIncrObjsFreed(); \
51035109
} while (0)
51045110

@@ -5108,12 +5114,12 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
51085114
Tcl_Obj *_objPtr; \
51095115
TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj)); \
51105116
TclNewObj(_objPtr); \
5111-
*(void **)&memPtr = (void *) _objPtr; \
5117+
*(void **)&(memPtr) = (void *)_objPtr; \
51125118
} while (0)
51135119

51145120
#define TclSmallFreeEx(interp, memPtr) \
51155121
do { \
5116-
Tcl_Obj *_objPtr = (Tcl_Obj *) memPtr; \
5122+
Tcl_Obj *_objPtr = (Tcl_Obj *)(memPtr); \
51175123
_objPtr->bytes = NULL; \
51185124
_objPtr->typePtr = NULL; \
51195125
_objPtr->refCount = 1; \

generic/tclRegexp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ TclRegAbout(
677677
*/
678678

679679
TclNewObj(resultObj);
680-
TclNewIntObj(infoObj, regexpPtr->re.re_nsub);
680+
TclNewIndexObj(infoObj, regexpPtr->re.re_nsub);
681681
Tcl_ListObjAppendElement(NULL, resultObj, infoObj);
682682

683683
/*

generic/tclScan.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct {
3434
Tcl_UniChar end;
3535
} Range;
3636

37-
typedef struct CharSet {
37+
typedef struct {
3838
int exclude; /* 1 if this is an exclusion set. */
3939
int nchars;
4040
Tcl_UniChar *chars;
@@ -1089,7 +1089,7 @@ Tcl_ScanObjCmd(
10891089
if (code == TCL_OK) {
10901090
if (underflow && (nconversions == 0)) {
10911091
if (numVars) {
1092-
TclNewIntObj(objPtr, TCL_INDEX_NONE);
1092+
TclNewIndexObj(objPtr, TCL_INDEX_NONE);
10931093
} else {
10941094
if (objPtr) {
10951095
Tcl_SetListObj(objPtr, 0, NULL);

generic/tclStringObj.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ TclStringFirst(
36883688
}
36893689
}
36903690
firstEnd:
3691-
TclNewIntObj(result, value);
3691+
TclNewIndexObj(result, value);
36923692
return result;
36933693
}
36943694

@@ -3775,7 +3775,7 @@ TclStringLast(
37753775
checkStr--;
37763776
}
37773777
lastEnd:
3778-
TclNewIntObj(result, value);
3778+
TclNewIndexObj(result, value);
37793779
return result;
37803780
}
37813781

0 commit comments

Comments
 (0)