diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 12:50:04 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 12:50:04 (GMT) |
commit | 84b9d03fb02b9ee744e03775f590d49f105d23f8 (patch) | |
tree | 5744c424eb00548acf667916895305f874909917 | |
parent | 2ed71e62a0e1b2fc0b0dca264ffa417ba2d9b159 (diff) | |
parent | a2a03ea8fb6718cc472cc7dcb44f8e68aadb24ba (diff) | |
download | tcl-84b9d03fb02b9ee744e03775f590d49f105d23f8.zip tcl-84b9d03fb02b9ee744e03775f590d49f105d23f8.tar.gz tcl-84b9d03fb02b9ee744e03775f590d49f105d23f8.tar.bz2 |
TIP 537 implementation: Enable 64-bit indexes in regexp matching
-rw-r--r-- | doc/RegExp.3 | 16 | ||||
-rw-r--r-- | doc/Utf.3 | 2 | ||||
-rw-r--r-- | generic/regcomp.c | 5 | ||||
-rw-r--r-- | generic/regex.h | 7 | ||||
-rw-r--r-- | generic/regexec.c | 6 | ||||
-rw-r--r-- | generic/tcl.h | 10 | ||||
-rw-r--r-- | generic/tclCmdMZ.c | 66 | ||||
-rw-r--r-- | generic/tclEnv.c | 4 | ||||
-rw-r--r-- | generic/tclInt.decls | 4 | ||||
-rw-r--r-- | generic/tclInt.h | 3 | ||||
-rw-r--r-- | generic/tclIntDecls.h | 4 | ||||
-rw-r--r-- | generic/tclRegexp.c | 18 | ||||
-rw-r--r-- | generic/tclStringObj.c | 8 | ||||
-rw-r--r-- | generic/tclTest.c | 29 | ||||
-rw-r--r-- | generic/tclUtf.c | 2 | ||||
-rw-r--r-- | generic/tclUtil.c | 14 |
16 files changed, 96 insertions, 102 deletions
diff --git a/doc/RegExp.3 b/doc/RegExp.3 index aa757bc..95716e9 100644 --- a/doc/RegExp.3 +++ b/doc/RegExp.3 @@ -64,7 +64,7 @@ identifies the beginning of the larger string. If it is not the same as \fItext\fR, then no .QW \fB^\fR matches will be allowed. -.AP int index in +.AP size_t index in Specifies which range is desired: 0 means the range of the entire match, 1 or greater means the range that matched a parenthesized sub-expression. @@ -80,14 +80,14 @@ OR-ed combination of the compilation flags \fBTCL_REG_ADVANCED\fR, \fBTCL_REG_QUOTE\fR, \fBTCL_REG_NOCASE\fR, \fBTCL_REG_NEWLINE\fR, \fBTCL_REG_NLSTOP\fR, \fBTCL_REG_NLANCH\fR, \fBTCL_REG_NOSUB\fR, and \fBTCL_REG_CANMATCH\fR. See below for more information. -.AP int offset in +.AP size_t offset in The character offset into the text where matching should begin. The value of the offset has no impact on \fB^\fR matches. This behavior is controlled by \fIeflags\fR. -.AP int nmatches in +.AP size_t nmatches in The number of matching subexpressions that should be remembered for later use. If this value is 0, then no subexpression match -information will be computed. If the value is \-1, then +information will be computed. If the value is TCL_INDEX_NONE, then all of the matching subexpressions will be remembered. Any other value will be taken as the maximum number of subexpressions to remember. @@ -337,9 +337,9 @@ defined as follows: .PP .CS typedef struct Tcl_RegExpInfo { - int \fInsubs\fR; + size_t \fInsubs\fR; Tcl_RegExpIndices *\fImatches\fR; - long \fIextendStart\fR; + size_t \fIextendStart\fR; } \fBTcl_RegExpInfo\fR; .CE .PP @@ -355,8 +355,8 @@ follows: .PP .CS typedef struct Tcl_RegExpIndices { - long \fIstart\fR; - long \fIend\fR; + size_t \fIstart\fR; + size_t \fIend\fR; } \fBTcl_RegExpIndices\fR; .CE .PP @@ -244,7 +244,7 @@ characters. \fBTcl_UtfAtIndex\fR returns a pointer to the specified character (not byte) \fIindex\fR in the UTF-8 string \fIsrc\fR. The source string must contain at least \fIindex\fR characters. This is equivalent to calling -\fBTcl_UtfNext\fR \fIindex\fR times. If \fIindex\fR is TCL_AUTO_LENGTH, +\fBTcl_UtfNext\fR \fIindex\fR times. If \fIindex\fR is TCL_INDEX_NONE, the return pointer points to the first character in the source string. .PP \fBTcl_UtfBackslash\fR is a utility procedure used by several of the Tcl diff --git a/generic/regcomp.c b/generic/regcomp.c index 47f06c8..9bf862c 100644 --- a/generic/regcomp.c +++ b/generic/regcomp.c @@ -338,7 +338,6 @@ compile( v->spaceused = 0; re->re_magic = REMAGIC; re->re_info = 0; /* bits get set during parse */ - re->re_csize = sizeof(chr); re->re_guts = NULL; re->re_fns = (void*)(&functions); @@ -2085,8 +2084,8 @@ dump( } fprintf(f, "\n\n\n========= DUMP ==========\n"); - fprintf(f, "nsub %d, info 0%lo, csize %d, ntree %d\n", - (int) re->re_nsub, re->re_info, re->re_csize, g->ntree); + fprintf(f, "nsub %" TCL_Z_MODIFIER "d, info 0%lo, ntree %d\n", + re->re_nsub, re->re_info, g->ntree); dumpcolors(&g->cmap, f); if (!NULLCNFA(g->search)) { diff --git a/generic/regex.h b/generic/regex.h index 81f98a4..47a8103 100644 --- a/generic/regex.h +++ b/generic/regex.h @@ -117,8 +117,8 @@ extern "C" { /* the biggie, a compiled RE (or rather, a front end to same) */ typedef struct { int re_magic; /* magic number */ - size_t re_nsub; /* number of subexpressions */ long re_info; /* information about RE */ + size_t re_nsub; /* number of subexpressions */ #define REG_UBACKREF 000001 #define REG_ULOOKAHEAD 000002 #define REG_UBOUNDS 000004 @@ -133,7 +133,6 @@ typedef struct { #define REG_UEMPTYMATCH 004000 #define REG_UIMPOSSIBLE 010000 #define REG_USHORTEST 020000 - int re_csize; /* sizeof(character) */ char *re_endp; /* backward compatibility kludge */ /* the rest is opaque pointers to hidden innards */ char *re_guts; /* `char *' is more portable than `void *' */ @@ -142,8 +141,8 @@ typedef struct { /* result reporting (may acquire more fields later) */ typedef struct { - long rm_so; /* start of substring */ - long rm_eo; /* end of substring */ + size_t rm_so; /* start of substring */ + size_t rm_eo; /* end of substring */ } regmatch_t; /* supplementary control and reporting */ diff --git a/generic/regexec.c b/generic/regexec.c index c57f42c..5ad8b17 100644 --- a/generic/regexec.c +++ b/generic/regexec.c @@ -187,10 +187,6 @@ exec( FreeVars(v); return REG_INVARG; } - if (re->re_csize != sizeof(chr)) { - FreeVars(v); - return REG_MIXED; - } /* * Setup. @@ -889,7 +885,7 @@ cbrdissect( MDEBUG(("cbackref n%d %d{%d-%d}\n", t->id, n, min, max)); /* get the backreferenced string */ - if (v->pmatch[n].rm_so == -1) { + if (v->pmatch[n].rm_so == (size_t)-1) { return REG_NOMATCH; } brstring = v->start + v->pmatch[n].rm_so; diff --git a/generic/tcl.h b/generic/tcl.h index 3cf6fad..46561b5 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -459,19 +459,18 @@ typedef void (Tcl_ThreadCreateProc) (void *clientData); */ typedef struct Tcl_RegExpIndices { - long start; /* Character offset of first character in + size_t start; /* Character offset of first character in * match. */ - long end; /* Character offset of first character after + size_t end; /* Character offset of first character after * the match. */ } Tcl_RegExpIndices; typedef struct Tcl_RegExpInfo { - int nsubs; /* Number of subexpressions in the compiled + size_t nsubs; /* Number of subexpressions in the compiled * expression. */ Tcl_RegExpIndices *matches; /* Array of nsubs match offset pairs. */ - long extendStart; /* The offset at which a subsequent match + size_t extendStart; /* The offset at which a subsequent match * might begin. */ - long reserved; /* Reserved for later use. */ } Tcl_RegExpInfo; /* @@ -2171,6 +2170,7 @@ typedef int (Tcl_ArgvGenFuncProc)(void *clientData, Tcl_Interp *interp, #define TCL_IO_FAILURE ((size_t)-1) #define TCL_AUTO_LENGTH ((size_t)-1) +#define TCL_INDEX_NONE ((size_t)-1) /* *---------------------------------------------------------------------------- diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index d02a159..e1c2960 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -127,9 +127,8 @@ Tcl_RegexpObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - size_t offset; + size_t offset, stringLength, matchLength, cflags, eflags; int i, indices, match, about, all, doinline, numMatchesSaved; - int cflags, eflags, stringLength, matchLength; Tcl_RegExp regExpr; Tcl_Obj *objPtr, *startIndex = NULL, *resultPtr = NULL; Tcl_RegExpInfo info; @@ -309,7 +308,7 @@ Tcl_RegexpObjCmd( if (offset == TCL_INDEX_START) { eflags = 0; - } else if (offset + 1 > (size_t)stringLength + 1) { + } else if (offset + 1 > stringLength + 1) { eflags = TCL_REG_NOTBOL; } else if (Tcl_GetUniChar(objPtr, offset-1) == '\n') { eflags = 0; @@ -365,7 +364,7 @@ Tcl_RegexpObjCmd( Tcl_Obj *newPtr; if (indices) { - int start, end; + size_t start, end; Tcl_Obj *objs[2]; /* @@ -373,7 +372,7 @@ Tcl_RegexpObjCmd( * area. (Scriptics Bug 4391/SF Bug #219232) */ - if (i <= info.nsubs && info.matches[i].start >= 0) { + if (i <= (int)info.nsubs && info.matches[i].start != TCL_INDEX_NONE) { start = offset + info.matches[i].start; end = offset + info.matches[i].end; @@ -382,20 +381,20 @@ Tcl_RegexpObjCmd( * match instead of the first character after the match. */ - if ((size_t)end + 1 >= offset + 1) { + if (end + 1 >= offset + 1) { end--; } } else { - start = -1; - end = -1; + start = TCL_INDEX_NONE; + end = TCL_INDEX_NONE; } - objs[0] = Tcl_NewWideIntObj(start); - objs[1] = Tcl_NewWideIntObj(end); + objs[0] = TclNewWideIntObjFromSize(start); + objs[1] = TclNewWideIntObjFromSize(end); newPtr = Tcl_NewListObj(2, objs); } else { - if (i <= info.nsubs) { + if (i <= (int)info.nsubs) { newPtr = Tcl_GetRange(objPtr, offset + info.matches[i].start, offset + info.matches[i].end - 1); @@ -445,7 +444,7 @@ Tcl_RegexpObjCmd( offset++; } all++; - if (offset + 1 >= (size_t)stringLength + 1) { + if (offset + 1 >= stringLength + 1) { break; } } @@ -488,9 +487,9 @@ Tcl_RegsubObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int idx, result, cflags, all, numMatches; - size_t wlen, wsublen = 0, offset; - int start, end, subStart, subEnd, match, command, numParts; + int result, cflags, all, match, command, numParts; + size_t idx, wlen, wsublen = 0, offset, numMatches; + size_t start, end, subStart, subEnd; Tcl_RegExp regExpr; Tcl_RegExpInfo info; Tcl_Obj *resultPtr, *subPtr, *objPtr, *startIndex = NULL; @@ -513,7 +512,7 @@ Tcl_RegsubObjCmd( command = 0; resultPtr = NULL; - for (idx = 1; idx < objc; idx++) { + for (idx = 1; idx < (size_t)objc; idx++) { const char *name; int index; @@ -549,7 +548,7 @@ Tcl_RegsubObjCmd( break; case REGSUB_START: { size_t temp; - if (++idx >= objc) { + if (++idx >= (size_t)objc) { goto endOfForLoop; } if (TclGetIntForIndexM(interp, objv[idx], TCL_INDEX_START, &temp) != TCL_OK) { @@ -569,7 +568,7 @@ Tcl_RegsubObjCmd( } endOfForLoop: - if (objc-idx < 3 || objc-idx > 4) { + if ((size_t)objc < idx + 3 || (size_t)objc > idx + 4) { Tcl_WrongNumArgs(interp, 1, objv, "?-option ...? exp string subSpec ?varName?"); optionError: @@ -1269,7 +1268,7 @@ Tcl_SplitObjCmd( Tcl_ListObjAppendElement(NULL, listPtr, objPtr); } else { const char *element, *p, *splitEnd; - int splitLen; + size_t splitLen; Tcl_UniChar splitChar = 0; /* @@ -1982,8 +1981,7 @@ StringMapCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - size_t length1, length2; - int mapElemc, index; + size_t length1, length2, mapElemc, index; int nocase = 0, mapWithDict = 0, copySource = 0; Tcl_Obj **mapElemv, *sourceObj, *resultPtr; Tcl_UniChar *ustring1, *ustring2, *p, *end; @@ -2024,8 +2022,8 @@ StringMapCmd( * sure. This shortens this code quite a bit. */ - Tcl_DictObjSize(interp, objv[objc-2], &mapElemc); - if (mapElemc == 0) { + Tcl_DictObjSize(interp, objv[objc-2], &i); + if (i == 0) { /* * Empty charMap, just return whatever string was given. */ @@ -2034,7 +2032,7 @@ StringMapCmd( return TCL_OK; } - mapElemc *= 2; + mapElemc = 2 * i; mapWithDict = 1; /* @@ -2045,15 +2043,17 @@ StringMapCmd( mapElemv = TclStackAlloc(interp, sizeof(Tcl_Obj *) * mapElemc); Tcl_DictObjFirst(interp, objv[objc-2], &search, mapElemv+0, mapElemv+1, &done); - for (i=2 ; i<mapElemc ; i+=2) { - Tcl_DictObjNext(&search, mapElemv+i, mapElemv+i+1, &done); + for (index=2 ; index<mapElemc ; index+=2) { + Tcl_DictObjNext(&search, mapElemv+index, mapElemv+index+1, &done); } Tcl_DictObjDone(&search); } else { - if (TclListObjGetElements(interp, objv[objc-2], &mapElemc, + int i; + if (TclListObjGetElements(interp, objv[objc-2], &i, &mapElemv) != TCL_OK) { return TCL_ERROR; } + mapElemc = i; if (mapElemc == 0) { /* * empty charMap, just return whatever string was given. @@ -3484,9 +3484,9 @@ TclNRSwitchObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int i,j, index, mode, foundmode, splitObjs, numMatchesSaved; + int i, index, mode, foundmode, splitObjs, numMatchesSaved; int noCase; - size_t patternLength; + size_t patternLength, j; const char *pattern; Tcl_Obj *stringObj, *indexVarObj, *matchVarObj; Tcl_Obj *const *savedObjv = objv; @@ -3797,9 +3797,9 @@ TclNRSwitchObjCmd( if (indexVarObj != NULL) { Tcl_Obj *rangeObjAry[2]; - if (info.matches[j].end > 0) { - rangeObjAry[0] = Tcl_NewWideIntObj(info.matches[j].start); - rangeObjAry[1] = Tcl_NewWideIntObj(info.matches[j].end-1); + if (info.matches[j].end + 1 > 1) { + rangeObjAry[0] = TclNewWideIntObjFromSize(info.matches[j].start); + rangeObjAry[1] = TclNewWideIntObjFromSize(info.matches[j].end-1); } else { rangeObjAry[0] = rangeObjAry[1] = Tcl_NewWideIntObj(-1); } @@ -3916,7 +3916,7 @@ TclNRSwitchObjCmd( } for (j = i + 1; ; j += 2) { - if (j >= objc) { + if (j >= (size_t)objc) { /* * This shouldn't happen since we've checked that the last body is * not a continuation... diff --git a/generic/tclEnv.c b/generic/tclEnv.c index 8598b9a..49b544d 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -230,7 +230,7 @@ TclSetEnv( Tcl_MutexLock(&envMutex); index = TclpFindVariable(name, &length); - if (index == TCL_AUTO_LENGTH) { + if (index == TCL_INDEX_NONE) { #ifndef USE_PUTENV /* * We need to handle the case where the environment may be changed @@ -314,7 +314,7 @@ TclSetEnv( * string in the cache. */ - if ((index != TCL_AUTO_LENGTH) && (environ[index] == p)) { + if ((index != TCL_INDEX_NONE) && (environ[index] == p)) { ReplaceString(oldValue, p); #ifdef HAVE_PUTENV_THAT_COPIES } else { diff --git a/generic/tclInt.decls b/generic/tclInt.decls index 2a66d18..bcdea6c 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -615,8 +615,8 @@ declare 150 { int TclRegAbout(Tcl_Interp *interp, Tcl_RegExp re) } declare 151 { - void TclRegExpRangeUniChar(Tcl_RegExp re, size_t index, int *startPtr, - int *endPtr) + void TclRegExpRangeUniChar(Tcl_RegExp re, size_t index, size_t *startPtr, + size_t *endPtr) } declare 152 { void TclSetLibraryPath(Tcl_Obj *pathPtr) diff --git a/generic/tclInt.h b/generic/tclInt.h index 6f61f1a..33462c04 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4128,7 +4128,6 @@ MODULE_SCOPE size_t TclIndexDecode(int encoded, size_t endValue); /* Constants used in index value encoding routines. */ #define TCL_INDEX_END ((size_t)-2) -#define TCL_INDEX_NONE ((size_t)-1) /* Index out of range or END+1 */ #define TCL_INDEX_START ((size_t)0) /* @@ -4972,7 +4971,7 @@ MODULE_SCOPE Tcl_PackageInitProc Procbodytest_SafeInit; # define TclNewWideIntObjFromSize(value) \ Tcl_NewWideIntObj(TclWideIntFromSize(value)) #else -# define TclWideIntFromSize(value) (value) +# define TclWideIntFromSize(value) ((Tcl_WideInt)(value)) # define TclNewWideIntObjFromSize Tcl_NewWideIntObj #endif diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index 2d4817b..260ef3e 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -334,7 +334,7 @@ EXTERN void TclHandleRelease(TclHandle handle); EXTERN int TclRegAbout(Tcl_Interp *interp, Tcl_RegExp re); /* 151 */ EXTERN void TclRegExpRangeUniChar(Tcl_RegExp re, size_t index, - int *startPtr, int *endPtr); + size_t *startPtr, size_t *endPtr); /* 152 */ EXTERN void TclSetLibraryPath(Tcl_Obj *pathPtr); /* 153 */ @@ -739,7 +739,7 @@ typedef struct TclIntStubs { TclHandle (*tclHandlePreserve) (TclHandle handle); /* 148 */ void (*tclHandleRelease) (TclHandle handle); /* 149 */ int (*tclRegAbout) (Tcl_Interp *interp, Tcl_RegExp re); /* 150 */ - void (*tclRegExpRangeUniChar) (Tcl_RegExp re, size_t index, int *startPtr, int *endPtr); /* 151 */ + void (*tclRegExpRangeUniChar) (Tcl_RegExp re, size_t index, size_t *startPtr, size_t *endPtr); /* 151 */ void (*tclSetLibraryPath) (Tcl_Obj *pathPtr); /* 152 */ Tcl_Obj * (*tclGetLibraryPath) (void); /* 153 */ void (*reserved154)(void); diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index 67195bb..5df76c3 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -264,7 +264,7 @@ Tcl_RegExpRange( if (index > regexpPtr->re.re_nsub) { *startPtr = *endPtr = NULL; - } else if (regexpPtr->matches[index].rm_so == -1) { + } else if (regexpPtr->matches[index].rm_so == (size_t)-1) { *startPtr = *endPtr = NULL; } else { if (regexpPtr->objPtr) { @@ -363,21 +363,21 @@ TclRegExpRangeUniChar( * passed to Tcl_RegExpExec. */ size_t index, /* 0 means give the range of the entire match, * > 0 means give the range of a matching - * subrange, -1 means the range of the + * subrange, TCL_INDEX_NONE means the range of the * rm_extend field. */ - int *startPtr, /* Store address of first character in + size_t *startPtr, /* Store address of first character in * (sub-)range here. */ - int *endPtr) /* Store address of character just after last + size_t *endPtr) /* Store address of character just after last * in (sub-)range here. */ { TclRegexp *regexpPtr = (TclRegexp *) re; - if ((regexpPtr->flags®_EXPECT) && index == TCL_AUTO_LENGTH) { + if ((regexpPtr->flags®_EXPECT) && (index == TCL_INDEX_NONE)) { *startPtr = regexpPtr->details.rm_extend.rm_so; *endPtr = regexpPtr->details.rm_extend.rm_eo; - } else if (index > regexpPtr->re.re_nsub) { - *startPtr = -1; - *endPtr = -1; + } else if (index + 1 > regexpPtr->re.re_nsub + 1) { + *startPtr = TCL_INDEX_NONE; + *endPtr = TCL_INDEX_NONE; } else { *startPtr = regexpPtr->matches[index].rm_so; *endPtr = regexpPtr->matches[index].rm_eo; @@ -677,7 +677,7 @@ TclRegAbout( resultObj = Tcl_NewObj(); Tcl_ListObjAppendElement(NULL, resultObj, - Tcl_NewWideIntObj((Tcl_WideInt) regexpPtr->re.re_nsub)); + TclNewWideIntObjFromSize(regexpPtr->re.re_nsub)); /* * Now append a list of all the bit-flags set for the RE. diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index a18c13e..f74d13d 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1404,7 +1404,7 @@ AppendUnicodeToUnicodeRep( numChars = stringPtr->numChars + appendNumChars; if (numChars > stringPtr->maxChars) { - size_t offset = TCL_AUTO_LENGTH; + size_t index = TCL_INDEX_NONE; /* * Protect against case where unicode points into the existing @@ -1414,7 +1414,7 @@ AppendUnicodeToUnicodeRep( if (unicode && unicode >= stringPtr->unicode && unicode <= stringPtr->unicode + stringPtr->maxChars) { - offset = unicode - stringPtr->unicode; + index = unicode - stringPtr->unicode; } GrowUnicodeBuffer(objPtr, numChars); @@ -1424,8 +1424,8 @@ AppendUnicodeToUnicodeRep( * Relocate unicode if needed; see above. */ - if (offset != TCL_AUTO_LENGTH) { - unicode = stringPtr->unicode + offset; + if (index != TCL_INDEX_NONE) { + unicode = stringPtr->unicode + index; } } diff --git a/generic/tclTest.c b/generic/tclTest.c index 450d663..1a975e2 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -345,7 +345,7 @@ static int TestreturnObjCmd(void *dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static void TestregexpXflags(const char *string, - int length, int *cflagsPtr, int *eflagsPtr); + size_t length, int *cflagsPtr, int *eflagsPtr); static int TestsaveresultCmd(void *dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -4007,12 +4007,12 @@ TestregexpObjCmd( if (objc > 2 && (cflags®_EXPECT) && indices) { const char *varName; const char *value; - int start, end; + size_t start, end; char resinfo[TCL_INTEGER_SPACE * 2]; varName = Tcl_GetString(objv[2]); TclRegExpRangeUniChar(regExpr, -1, &start, &end); - sprintf(resinfo, "%d %d", start, end-1); + sprintf(resinfo, "%" TCL_LL_MODIFIER "d %" TCL_LL_MODIFIER "d", TclWideIntFromSize(start), TclWideIntFromSize(end-1)); value = Tcl_SetVar2(interp, varName, NULL, resinfo, 0); if (value == NULL) { Tcl_AppendResult(interp, "couldn't set variable \"", @@ -4026,7 +4026,7 @@ TestregexpObjCmd( Tcl_RegExpGetInfo(regExpr, &info); varName = Tcl_GetString(objv[2]); - sprintf(resinfo, "%ld", info.extendStart); + sprintf(resinfo, "%" TCL_LL_MODIFIER "d", TclWideIntFromSize(info.extendStart)); value = Tcl_SetVar2(interp, varName, NULL, resinfo, 0); if (value == NULL) { Tcl_AppendResult(interp, "couldn't set variable \"", @@ -4047,7 +4047,7 @@ TestregexpObjCmd( Tcl_RegExpGetInfo(regExpr, &info); for (i = 0; i < objc; i++) { - int start, end; + size_t start, end; Tcl_Obj *newPtr, *varPtr, *valuePtr; varPtr = objv[i]; @@ -4057,9 +4057,9 @@ TestregexpObjCmd( if (ii == TCL_INDEX_NONE) { TclRegExpRangeUniChar(regExpr, ii, &start, &end); - } else if (ii > (size_t)info.nsubs) { - start = -1; - end = -1; + } else if (ii > info.nsubs) { + start = TCL_INDEX_NONE; + end = TCL_INDEX_NONE; } else { start = info.matches[ii].start; end = info.matches[ii].end; @@ -4070,19 +4070,19 @@ TestregexpObjCmd( * instead of the first character after the match. */ - if (end >= 0) { + if (end != TCL_INDEX_NONE) { end--; } - objs[0] = Tcl_NewWideIntObj(start); - objs[1] = Tcl_NewWideIntObj(end); + objs[0] = TclNewWideIntObjFromSize(start); + objs[1] = TclNewWideIntObjFromSize(end); newPtr = Tcl_NewListObj(2, objs); } else { if (ii == TCL_INDEX_NONE) { TclRegExpRangeUniChar(regExpr, ii, &start, &end); newPtr = Tcl_GetRange(objPtr, start, end); - } else if (ii > (size_t)info.nsubs) { + } else if (ii > info.nsubs) { newPtr = Tcl_NewObj(); } else { newPtr = Tcl_GetRange(objPtr, info.matches[ii].start, @@ -4123,11 +4123,12 @@ TestregexpObjCmd( static void TestregexpXflags( const char *string, /* The string of flags. */ - int length, /* The length of the string in bytes. */ + size_t length, /* The length of the string in bytes. */ int *cflagsPtr, /* compile flags word */ int *eflagsPtr) /* exec flags word */ { - int i, cflags, eflags; + size_t i; + int cflags, eflags; cflags = *cflagsPtr; eflags = *eflagsPtr; diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 6a40856..5177fd0 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1027,7 +1027,7 @@ Tcl_UtfAtIndex( size_t len = 0; #endif - if (index != TCL_AUTO_LENGTH) { + if (index != TCL_INDEX_NONE) { while (index--) { #if TCL_UTF_MAX <= 4 src += (len = TclUtfToUniChar(src, &ch)); diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 7373085..c9eb8d2 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2637,10 +2637,10 @@ Tcl_DStringInit( char * Tcl_DStringAppend( Tcl_DString *dsPtr, /* Structure describing dynamic string. */ - const char *bytes, /* String to append. If length is -1 then this - * must be null-terminated. */ + const char *bytes, /* String to append. If length is + * TCL_AUTO_LENGTH then this must be null-terminated. */ size_t length) /* Number of bytes from "bytes" to append. If - * -1, then append all of bytes, up to null + * TCL_AUTO_LENGTH, then append all of bytes, up to null * at end. */ { size_t newSize; @@ -2664,18 +2664,18 @@ Tcl_DStringAppend( memcpy(newString, dsPtr->string, dsPtr->length); dsPtr->string = newString; } else { - size_t offset = TCL_AUTO_LENGTH; + size_t index = TCL_INDEX_NONE; /* See [16896d49fd] */ if (bytes >= dsPtr->string && bytes <= dsPtr->string + dsPtr->length) { - offset = bytes - dsPtr->string; + index = bytes - dsPtr->string; } dsPtr->string = Tcl_Realloc(dsPtr->string, dsPtr->spaceAvl); - if (offset != TCL_AUTO_LENGTH) { - bytes = dsPtr->string + offset; + if (index != TCL_INDEX_NONE) { + bytes = dsPtr->string + index; } } } |