diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2007-03-10 14:57:36 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2007-03-10 14:57:36 (GMT) |
commit | 9b37ffdd3cd479883df0f3aacbd2e442b40fd5e4 (patch) | |
tree | 4c34e2b06eddc7337a184990ead7f7016e28f670 | |
parent | 3550b2068c9275350ca9f9ab2536ff8bf09ec1fe (diff) | |
download | tcl-9b37ffdd3cd479883df0f3aacbd2e442b40fd5e4.zip tcl-9b37ffdd3cd479883df0f3aacbd2e442b40fd5e4.tar.gz tcl-9b37ffdd3cd479883df0f3aacbd2e442b40fd5e4.tar.bz2 |
Fix [Bug 1675116] in a way suitable for 8.4.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 14 | ||||
-rw-r--r-- | tests/cmdIL.test | 7 |
3 files changed, 25 insertions, 2 deletions
@@ -1,3 +1,9 @@ +2007-03-10 Donal K. Fellows <donal.k.fellows@man.ac.uk> + + * generic/tclCmdIL.c (Tcl_LsortObjCmd): Handle tricky case with loss + * tests/cmdIL.test (cmdIL-1.29):of list rep during sorting due + to shimmering. [Bug 1675116] + 2007-03-07 Daniel Steffen <das@users.sourceforge.net> * macosx/tclMacOSXNotify.c: add spinlock debugging and sanity checks. diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index d44ba7a..85e51d0 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.47.2.10 2006/11/28 22:20:00 andreas_kupries Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.47.2.11 2007/03/10 14:57:38 dkf Exp $ */ #include "tclInt.h" @@ -3799,6 +3799,15 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv) elementArray[i].objPtr = listObjPtrs[i]; elementArray[i].count = 0; elementArray[i].nextPtr = &elementArray[i+1]; + + /* + * When sorting using a command, we are reentrant and therefore might + * have the representation of the list being sorted shimmered out from + * underneath our feet. Increment the reference counts of the elements + * to sort to prevent this. [Bug 1675116] + */ + + Tcl_IncrRefCount(elementArray[i].objPtr); } elementArray[length-1].nextPtr = NULL; elementPtr = MergeSort(elementArray, &sortInfo); @@ -3824,6 +3833,9 @@ Tcl_LsortObjCmd(clientData, interp, objc, objv) } } } + for (i=0; i<length; i++) { + Tcl_DecrRefCount(elementArray[i].objPtr); + } ckfree((char*) elementArray); done: diff --git a/tests/cmdIL.test b/tests/cmdIL.test index 6376a12..2148dd1 100644 --- a/tests/cmdIL.test +++ b/tests/cmdIL.test @@ -8,7 +8,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: cmdIL.test,v 1.14.6.1 2003/07/15 15:44:52 dkf Exp $ +# RCS: @(#) $Id: cmdIL.test,v 1.14.6.2 2007/03/10 14:57:38 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -104,6 +104,11 @@ test cmdIL-1.25 {Tcl_LsortObjCmd procedure, order of -index and -command} { test cmdIL-1.26 {Tcl_LsortObjCmd procedure, offset indexing from end} { lsort -index end-1 {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}} } {{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}} +test cmdIL-1.29 {Tcl_LsortObjCmd procedure, loss of list rep during sorting} { + set l {1 2 3} + proc testcmp args {string length $::l} + string length [lsort -command testcmp $l] +} 5 # Can't think of any good tests for the MergeSort and MergeLists # procedures, except a bunch of random lists to sort. |