summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpooryorick <com.digitalsmarties@pooryorick.com>2016-08-18 21:59:37 (GMT)
committerpooryorick <com.digitalsmarties@pooryorick.com>2016-08-18 21:59:37 (GMT)
commit46a04df737702095dbd3fd28e6b28088006b251f (patch)
tree52de45d803bca75dffff44640ba63b589a4f594d
parentf1810dae6c5de7512c2d388b7631b7dc4a888928 (diff)
downloadtcl-pyk_listdictstringrep.zip
tcl-pyk_listdictstringrep.tar.gz
tcl-pyk_listdictstringrep.tar.bz2
Add back constraint that direct dict->list conversion is only done when no string representation exists.pyk_listdictstringrep
-rw-r--r--generic/tclListObj.c15
-rw-r--r--tests/list.test7
2 files changed, 16 insertions, 6 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 0852c8c..362efa2 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -1827,11 +1827,6 @@ SetListFromAny(
List *listRepPtr;
Tcl_Obj **elemPtrs;
- /*
- * Dictionaries are a special case; they may have stored a previous list
- * representation
- */
-
listPtr = TclObjLookupTyped(objPtr, &tclListType);
if (listPtr != NULL) {
Tcl_IncrRefCount(listPtr);
@@ -1844,7 +1839,15 @@ SetListFromAny(
return TCL_OK;
}
- if (objPtr->typePtr == &tclDictType) {
+ /*
+ * Dictionaries are a special case; they have a string representation such
+ * that *all* valid dictionaries are valid lists. Hence we can convert
+ * more directly. Only do this when there's no existing string rep; if
+ * there is, it is the string rep that's authoritative (because it could
+ * describe duplicate keys).
+ */
+
+ if (objPtr->typePtr == &tclDictType && !objPtr->bytes) {
Tcl_Obj *keyPtr, *valuePtr;
Tcl_DictSearch search;
int done, size;
diff --git a/tests/list.test b/tests/list.test
index dff5d50..661ddde 100644
--- a/tests/list.test
+++ b/tests/list.test
@@ -129,6 +129,13 @@ test list-4.1 {Bug 3173086} {
string is list "{[list \\\\\}]}"
} 1
+test list-5.1 {list/dict conversions without} {
+ set a {a 1 a 2}
+ dict get $a a
+ lindex $a 1
+} 1
+
+
# cleanup
::tcltest::cleanupTests
return