summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-05-05 16:35:00 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-05-05 16:35:00 (GMT)
commit428644e1853798dec8416b023b9cfea053574e4b (patch)
tree6801818ca99f1fd4c859ecd74412c672848d8a7b /generic/tclListObj.c
parentaed8684173b0fe3f9627c9ff7343d176dfd1afa7 (diff)
downloadtcl-428644e1853798dec8416b023b9cfea053574e4b.zip
tcl-428644e1853798dec8416b023b9cfea053574e4b.tar.gz
tcl-428644e1853798dec8416b023b9cfea053574e4b.tar.bz2
Stop generating string rep of dict when converting to list.
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r--generic/tclListObj.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 164fa4a..a9c986b 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -589,7 +589,11 @@ Tcl_ListObjAppendElement(
if (listPtr->typePtr != &tclListType) {
int result, length;
- (void) TclGetStringFromObj(listPtr, &length);
+ if (listPtr->typePtr == &tclDictType) {
+ (void) Tcl_DictObjSize(NULL, listPtr, &length);
+ } else {
+ (void) TclGetStringFromObj(listPtr, &length);
+ }
if (!length) {
Tcl_SetListObj(listPtr, 1, &objPtr);
return TCL_OK;
@@ -700,7 +704,11 @@ Tcl_ListObjIndex(
if (listPtr->typePtr != &tclListType) {
int result, length;
- (void) TclGetStringFromObj(listPtr, &length);
+ if (listPtr->typePtr == &tclDictType) {
+ (void) Tcl_DictObjSize(NULL, listPtr, &length);
+ } else {
+ (void) TclGetStringFromObj(listPtr, &length);
+ }
if (!length) {
*objPtrPtr = NULL;
return TCL_OK;
@@ -755,7 +763,20 @@ Tcl_ListObjLength(
if (listPtr->typePtr != &tclListType) {
int result, length;
- (void) TclGetStringFromObj(listPtr, &length);
+ if (listPtr->typePtr == &tclDictType) {
+ (void) Tcl_DictObjSize(NULL, listPtr, &length);
+ /*
+ * It's tempting to just report 2*length as the list length
+ * of this dict, but arguably that's false since the max sizes
+ * for dicts and lists are not the same, so some dicts don't
+ * actually convert to lists, and it's good to get that error
+ * back from the SetListFromAny() call below instead of a false
+ * indication we can treat the value as a list. ([llength $val]
+ * often used as a "listiness" test)
+ */
+ } else {
+ (void) TclGetStringFromObj(listPtr, &length);
+ }
if (!length) {
*intPtr = 0;
return TCL_OK;
@@ -830,7 +851,11 @@ Tcl_ListObjReplace(
if (listPtr->typePtr != &tclListType) {
int length;
- (void) TclGetStringFromObj(listPtr, &length);
+ if (listPtr->typePtr == &tclDictType) {
+ (void) Tcl_DictObjSize(NULL, listPtr, &length);
+ } else {
+ (void) TclGetStringFromObj(listPtr, &length);
+ }
if (!length) {
if (objc) {
Tcl_SetListObj(listPtr, objc, NULL);
@@ -1526,7 +1551,11 @@ TclListObjSetElement(
if (listPtr->typePtr != &tclListType) {
int length, result;
- (void) TclGetStringFromObj(listPtr, &length);
+ if (listPtr->typePtr == &tclDictType) {
+ (void) Tcl_DictObjSize(NULL, listPtr, &length);
+ } else {
+ (void) TclGetStringFromObj(listPtr, &length);
+ }
if (!length) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("list index out of range", -1));