diff options
author | hobbs <hobbs> | 2003-02-11 21:54:38 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2003-02-11 21:54:38 (GMT) |
commit | 5ea88a91277fd9a447ef118a88f4699698335841 (patch) | |
tree | 0d749ad255e3fcc6ef1ada93e00ad67966ab069e | |
parent | 736f0317f936ab603c6157110e8efdeb4a329a86 (diff) | |
download | tcl-5ea88a91277fd9a447ef118a88f4699698335841.zip tcl-5ea88a91277fd9a447ef118a88f4699698335841.tar.gz tcl-5ea88a91277fd9a447ef118a88f4699698335841.tar.bz2 |
* tests/lsearch.test:
* generic/tclCmdIL.c (Tcl_LsearchObjCmd): protect against the case
that lsearch -regepx list and pattern objects are equal.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 21 | ||||
-rw-r--r-- | tests/lsearch.test | 7 |
3 files changed, 29 insertions, 3 deletions
@@ -6,6 +6,10 @@ 2003-02-11 Jeff Hobbs <jeffh@ActiveState.com> + * tests/lsearch.test: + * generic/tclCmdIL.c (Tcl_LsearchObjCmd): protect against the case + that lsearch -regepx list and pattern objects are equal. + * tests/stringObj.test: * generic/tclStringObj.c (Tcl_GetCharLength): correct ascii char opt of 2002-11-11 to not stop early on \x00. [Bug #684699] diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 36b1ef5..f464d25 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdIL.c,v 1.44 2002/06/11 13:22:36 msofer Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.45 2003/02/11 21:54:48 hobbs Exp $ */ #include "tclInt.h" @@ -2778,6 +2778,7 @@ Tcl_LsearchObjCmd(clientData, interp, objc, objv) int offset, allMatches, inlineReturn, negatedMatch; double patDouble, objDouble; Tcl_Obj *patObj, **listv, *listPtr, *startPtr; + Tcl_RegExp regexp; static CONST char *options[] = { "-all", "-ascii", "-decreasing", "-dictionary", "-exact", "-glob", "-increasing", "-inline", @@ -2890,6 +2891,21 @@ Tcl_LsearchObjCmd(clientData, interp, objc, objv) } } + if ((enum modes) mode == REGEXP) { + /* + * We can shimmer regexp/list if listv[i] == pattern, so get the + * regexp rep before the list rep. + */ + regexp = Tcl_GetRegExpFromObj(interp, objv[objc - 1], + TCL_REG_ADVANCED | TCL_REG_NOSUB); + if (regexp == NULL) { + if (startPtr) { + Tcl_DecrRefCount(startPtr); + } + return TCL_ERROR; + } + } + /* * Make sure the list argument is a list object and get its length and * a pointer to its array of element pointers. @@ -3085,8 +3101,9 @@ Tcl_LsearchObjCmd(clientData, interp, objc, objv) patternBytes); break; case REGEXP: - match = Tcl_RegExpMatchObj(interp, listv[i], patObj); + match = Tcl_RegExpExecObj(interp, regexp, listv[i], 0, 0, 0); if (match < 0) { + Tcl_DecrRefCount(patObj); if (listPtr) { Tcl_DecrRefCount(listPtr); } diff --git a/tests/lsearch.test b/tests/lsearch.test index 887edb9..da6dce6 100644 --- a/tests/lsearch.test +++ b/tests/lsearch.test @@ -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: lsearch.test,v 1.8 2002/03/06 11:28:08 dkf Exp $ +# RCS: @(#) $Id: lsearch.test,v 1.9 2003/02/11 21:54:48 hobbs Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -341,6 +341,11 @@ test lsearch-14.1 {make sure no shimmering occurs} { lsearch -start $x $x $x } 0 +test lsearch-15.1 {lsearch -regexp shared object} { + set str a + lsearch -regexp $str $str +} 0 + # cleanup catch {unset res} catch {unset increasingIntegers} |