summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--generic/tclCmdIL.c21
-rw-r--r--tests/lsearch.test7
3 files changed, 29 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d765792..711dfb3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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}