Skip to content

Commit

Permalink
Merge 8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Dec 29, 2023
2 parents 4c97b25 + b2d7ce5 commit a6b6453
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 76 deletions.
6 changes: 3 additions & 3 deletions generic/tclCmdMZ.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ Tcl_RegsubObjCmd(

Tcl_Size slen;
int nocase, wsrclc;
int (*strCmpFn)(const Tcl_UniChar*,const Tcl_UniChar*,unsigned long);
int (*strCmpFn)(const Tcl_UniChar*,const Tcl_UniChar*,size_t);
Tcl_UniChar *p;

numMatches = 0;
Expand Down Expand Up @@ -1968,7 +1968,7 @@ StringMapCmd(
int nocase = 0, mapWithDict = 0, copySource = 0;
Tcl_Obj **mapElemv, *sourceObj, *resultPtr;
Tcl_UniChar *ustring1, *ustring2, *p, *end;
int (*strCmpFn)(const Tcl_UniChar*, const Tcl_UniChar*, unsigned long);
int (*strCmpFn)(const Tcl_UniChar*, const Tcl_UniChar*, size_t);

if (objc < 3 || objc > 4) {
Tcl_WrongNumArgs(interp, 1, objv, "?-nocase? charMap string");
Expand Down Expand Up @@ -2076,7 +2076,7 @@ StringMapCmd(
}
end = ustring1 + length1;

strCmpFn = (nocase ? TclUniCharNcasecmp : TclUniCharNcmp);
strCmpFn = nocase ? TclUniCharNcasecmp : TclUniCharNcmp;

/*
* Force result to be Unicode
Expand Down
9 changes: 7 additions & 2 deletions generic/tclInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3484,9 +3484,14 @@ MODULE_SCOPE void TclZipfsFinalize(void);
MODULE_SCOPE int *TclGetUnicodeFromObj(Tcl_Obj *, int *);
MODULE_SCOPE Tcl_Obj *TclNewUnicodeObj(const int *, int);
MODULE_SCOPE void TclAppendUnicodeToObj(Tcl_Obj *, const int *, int);
MODULE_SCOPE int TclUniCharNcasecmp(const int *, const int *, unsigned long);
MODULE_SCOPE int TclUniCharNcasecmp(const int *, const int *, size_t);
MODULE_SCOPE int TclUniCharNcasememcmp(const void *, const void *, size_t);
MODULE_SCOPE int TclUniCharCaseMatch(const int *, const int *, int);
MODULE_SCOPE int TclUniCharNcmp(const int *, const int *, unsigned long);
MODULE_SCOPE int TclUniCharNcmp(const int *, const int *, size_t);
MODULE_SCOPE int TclUniCharNmemcmp(const void *, const void *, size_t);
MODULE_SCOPE int TclUtfNcasememcmp(const void *s1, const void *s2, size_t n);
MODULE_SCOPE int TclUtfNmemcmp(const void *s1, const void *s2, size_t n);


/*
* Many parsing tasks need a common definition of whitespace.
Expand Down
41 changes: 36 additions & 5 deletions generic/tclStringObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,38 @@ TclStringCat(
*---------------------------------------------------------------------------
*/

static int
UtfNmemcmp(
const void *csPtr, /* UTF string to compare to ct. */
const void *ctPtr, /* UTF string cs is compared to. */
size_t numBytes) /* Number of *bytes* to compare. */
{
const char *cs = (const char *)csPtr;
const char *ct = (const char *)ctPtr;
/*
* We can't simply call 'memcmp(cs, ct, numBytes);' because we need to
* check for Tcl's \xC0\x80 non-utf-8 null encoding. Otherwise utf-8 lexes
* fine in the strcmp manner.
*/

int result = 0;

for ( ; numBytes != 0; numBytes--, cs++, ct++) {
if (*cs != *ct) {
result = UCHAR(*cs) - UCHAR(*ct);
break;
}
}
if (numBytes && ((UCHAR(*cs) == 0xC0) || (UCHAR(*ct) == 0xC0))) {
unsigned char c1, c2;

c1 = ((UCHAR(*cs) == 0xC0) && (UCHAR(cs[1]) == 0x80)) ? 0 : UCHAR(*cs);
c2 = ((UCHAR(*ct) == 0xC0) && (UCHAR(ct[1]) == 0x80)) ? 0 : UCHAR(*ct);
result = (c1 - c2);
}
return result;
}

int
TclStringCmp(
Tcl_Obj *value1Ptr,
Expand Down Expand Up @@ -3852,7 +3884,7 @@ TclStringCmp(
if (nocase) {
s1 = (char *) TclGetUnicodeFromObj(value1Ptr, &s1len);
s2 = (char *) TclGetUnicodeFromObj(value2Ptr, &s2len);
memCmpFn = (memCmpFn_t)(void *)TclUniCharNcasecmp;
memCmpFn = TclUniCharNcasememcmp;
} else {
s1len = TclGetCharLength(value1Ptr);
s2len = TclGetCharLength(value2Ptr);
Expand Down Expand Up @@ -3883,7 +3915,7 @@ TclStringCmp(
reqlength *= sizeof(Tcl_UniChar);
}
} else {
memCmpFn = (memCmpFn_t)(void *)TclUniCharNcmp;
memCmpFn = TclUniCharNmemcmp;
}
}
}
Expand Down Expand Up @@ -3941,12 +3973,11 @@ TclStringCmp(
*/

if ((reqlength < 0) && !nocase) {
memCmpFn = (memCmpFn_t)(void *)TclpUtfNcmp2;
memCmpFn = UtfNmemcmp;
} else {
s1len = TclNumUtfChars(s1, s1len);
s2len = TclNumUtfChars(s2, s2len);
memCmpFn = (memCmpFn_t)(void *)
(nocase ? Tcl_UtfNcasecmp : Tcl_UtfNcmp);
memCmpFn = nocase ? TclUtfNcasememcmp : TclUtfNmemcmp;
}
}
}
Expand Down
Loading

0 comments on commit a6b6453

Please sign in to comment.