From 2ebefee1b05df6c41125e6bc8ed768c0cc4f50dc Mon Sep 17 00:00:00 2001 From: hobbs Date: Fri, 9 Nov 2007 18:55:13 +0000 Subject: * generic/tclInt.decls, generic/tclIntDecls.h: Use unsigned char for * generic/tclExecute.c, generic/tclUtil.c: TclByteArrayMatch and don't allow a nocase option. [Bug 1828296] For INST_STR_MATCH, ignore pattern type for TclByteArrayMatch case. --- ChangeLog | 7 ++++++- generic/tclExecute.c | 8 +++----- generic/tclInt.decls | 6 +++--- generic/tclIntDecls.h | 9 +++++---- generic/tclUtil.c | 53 ++++++++++++++++++--------------------------------- 5 files changed, 36 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9861697..52d7f8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ 2007-11-09 Jeff Hobbs + * generic/tclInt.decls, generic/tclIntDecls.h: Use unsigned char for + * generic/tclExecute.c, generic/tclUtil.c: TclByteArrayMatch + and don't allow a nocase option. [Bug 1828296] + For INST_STR_MATCH, ignore pattern type for TclByteArrayMatch case. + * generic/tclBinary.c (Tcl_GetByteArrayFromObj): check type before - func jump + func jump (perf) 2007-11-07 Jeff Hobbs diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 6f65c2a..6971a0a 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclExecute.c,v 1.341 2007/11/08 07:10:43 das Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.342 2007/11/09 18:55:14 hobbs Exp $ */ #include "tclInt.h" @@ -4063,15 +4063,13 @@ TclExecuteByteCode( ustring2 = Tcl_GetUnicodeFromObj(value2Ptr, &length2); match = TclUniCharMatch(ustring1, length1, ustring2, length2, nocase); - } else if ((valuePtr->typePtr == &tclByteArrayType) - || (value2Ptr->typePtr == &tclByteArrayType)) { + } else if ((valuePtr->typePtr == &tclByteArrayType) && !nocase) { unsigned char *string1, *string2; int length1, length2; string1 = Tcl_GetByteArrayFromObj(valuePtr, &length1); string2 = Tcl_GetByteArrayFromObj(value2Ptr, &length2); - match = TclByteArrayMatch((char*) string1, length1, - (char*) string2, length2, nocase); + match = TclByteArrayMatch(string1, length1, string2, length2); } else { match = Tcl_StringCaseMatch(TclGetString(valuePtr), TclGetString(value2Ptr), nocase); diff --git a/generic/tclInt.decls b/generic/tclInt.decls index bf92b7b..c3118df 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tclInt.decls,v 1.115 2007/11/08 00:50:31 hobbs Exp $ +# RCS: @(#) $Id: tclInt.decls,v 1.116 2007/11/09 18:55:15 hobbs Exp $ library tcl @@ -944,8 +944,8 @@ declare 236 generic { # Added for 8.5b3 to improve binary glob match case declare 237 generic { - int TclByteArrayMatch(CONST char *string, int strLen, - CONST char *pattern, int ptnLen, int nocase) + int TclByteArrayMatch(const unsigned char *string, int strLen, + const unsigned char *pattern, int ptnLen) } ############################################################################## diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index 76297aa..05daefb 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIntDecls.h,v 1.106 2007/11/08 00:50:32 hobbs Exp $ + * RCS: @(#) $Id: tclIntDecls.h,v 1.107 2007/11/09 18:55:15 hobbs Exp $ */ #ifndef _TCLINTDECLS @@ -1060,8 +1060,9 @@ EXTERN void TclBackgroundException (Tcl_Interp * interp, #ifndef TclByteArrayMatch_TCL_DECLARED #define TclByteArrayMatch_TCL_DECLARED /* 237 */ -EXTERN int TclByteArrayMatch (CONST char * string, int strLen, - CONST char * pattern, int ptnLen, int nocase); +EXTERN int TclByteArrayMatch (const unsigned char * string, + int strLen, const unsigned char * pattern, + int ptnLen); #endif typedef struct TclIntStubs { @@ -1320,7 +1321,7 @@ typedef struct TclIntStubs { Var * (*tclVarHashCreateVar) (TclVarHashTable * tablePtr, const char * key, int * newPtr); /* 234 */ void (*tclInitVarHashTable) (TclVarHashTable * tablePtr, Namespace * nsPtr); /* 235 */ void (*tclBackgroundException) (Tcl_Interp * interp, int code); /* 236 */ - int (*tclByteArrayMatch) (CONST char * string, int strLen, CONST char * pattern, int ptnLen, int nocase); /* 237 */ + int (*tclByteArrayMatch) (const unsigned char * string, int strLen, const unsigned char * pattern, int ptnLen); /* 237 */ } TclIntStubs; #ifdef __cplusplus diff --git a/generic/tclUtil.c b/generic/tclUtil.c index a95f250..815769a 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtil.c,v 1.85 2007/11/08 00:50:32 hobbs Exp $ + * RCS: @(#) $Id: tclUtil.c,v 1.86 2007/11/09 18:55:16 hobbs Exp $ */ #include "tclInt.h" @@ -1555,9 +1555,9 @@ Tcl_StringCaseMatch( * * TclByteArrayMatch -- * - * See if a particular string matches a particular pattern. Allows case - * insensitivity. - * Parallels tclUtf.c:TclUniCharMatch, adjusted for char*. + * See if a particular string matches a particular pattern. Does not + * allow for case insensitivity. + * Parallels tclUtf.c:TclUniCharMatch, adjusted for char* and sans nocase. * * Results: * The return value is 1 if string matches pattern, and 0 otherwise. The @@ -1572,15 +1572,14 @@ Tcl_StringCaseMatch( int TclByteArrayMatch( - CONST char *string, /* String. */ - int strLen, /* Length of String */ - CONST char *pattern, /* Pattern, which may contain special - * characters. */ - int ptnLen, /* Length of Pattern */ - int nocase) /* 0 for case sensitive, 1 for insensitive */ + const unsigned char *string, /* String. */ + int strLen, /* Length of String */ + const unsigned char *pattern, /* Pattern, which may contain special + * characters. */ + int ptnLen) /* Length of Pattern */ { - CONST char *stringEnd, *patternEnd; - char p; + const unsigned char *stringEnd, *patternEnd; + unsigned char p; stringEnd = string + strLen; patternEnd = pattern + ptnLen; @@ -1620,9 +1619,6 @@ TclByteArrayMatch( return 1; } p = *pattern; - if (nocase) { - p = tolower(p); - } while (1) { /* * Optimization for matching - cruise through the string @@ -1631,19 +1627,12 @@ TclByteArrayMatch( */ if ((p != '[') && (p != '?') && (p != '\\')) { - if (nocase) { - while ((string < stringEnd) && (p != *string) - && (p != tolower(*string))) { - string++; - } - } else { - while ((string < stringEnd) && (p != *string)) { - string++; - } + while ((string < stringEnd) && (p != *string)) { + string++; } } if (TclByteArrayMatch(string, stringEnd - string, - pattern, patternEnd - pattern, nocase)) { + pattern, patternEnd - pattern)) { return 1; } if (string == stringEnd) { @@ -1671,23 +1660,23 @@ TclByteArrayMatch( */ if (p == '[') { - char ch1, startChar, endChar; + unsigned char ch1, startChar, endChar; pattern++; - ch1 = (nocase ? tolower(*string) : *string); + ch1 = *string; string++; while (1) { if ((*pattern == ']') || (pattern == patternEnd)) { return 0; } - startChar = (nocase ? tolower(*pattern) : *pattern); + startChar = *pattern; pattern++; if (*pattern == '-') { pattern++; if (pattern == patternEnd) { return 0; } - endChar = (nocase ? tolower(*pattern) : *pattern); + endChar = *pattern; pattern++; if (((startChar <= ch1) && (ch1 <= endChar)) || ((endChar <= ch1) && (ch1 <= startChar))) { @@ -1727,11 +1716,7 @@ TclByteArrayMatch( * each string match. */ - if (nocase) { - if (tolower(*string) != tolower(*pattern)) { - return 0; - } - } else if (*string != *pattern) { + if (*string != *pattern) { return 0; } string++; -- cgit v0.12