Tcl Source Code

View Ticket
Login
Ticket UUID: 2008248
Title: dict to list changes element representations
Type: Bug Version: obsolete: 8.5.3
Submitter: ajpasadyn Created on: 2008-07-01 20:51:39
Subsystem: 14. List Object Assigned To: dkf
Priority: 7 High Severity:
Status: Closed Last Modified: 2008-07-21 05:06:20
Resolution: Fixed Closed By: dkf
    Closed on: 2008-07-20 22:06:20
Description:
I found an issue while using TclBlend in Tcl 8.5, and the attached script demonstrates it.  Basically, the conversion of an internal representation from list to dict is special cased to keep the representations of the elements, while the conversion from dict to list passes through a string-only representation.  This appears even in code that does not explicitly use dict because the array get and set have changed to use dict now.

TclBlend uses a special internal representation to hold references to Java objects, and if the internal representation is lost then the underlying object might get freed.  This violates the "everything is a string" but in the past it's been sufficient to just make sure that the Tcl script itself was careful with the references it obtained.  If the Tcl core changes internal representations beyond what is needed then an extension like this really does not seem to have much of a chance of working.
User Comments: dkf added on 2008-07-21 05:06:20:
Logged In: YES 
user_id=79902
Originator: NO

Backported to 8.5 branch. Patch actually used takes some shortcuts that your suggestion didn't (since I know what the pre- and post-conditions on the core dict API functions are) but is otherwise the same. Thanks.

dkf added on 2008-07-21 00:56:14:
Logged In: YES 
user_id=79902
Originator: NO

Fixed on HEAD. Backport needed.

dkf added on 2008-07-11 17:39:45:
Logged In: YES 
user_id=79902
Originator: NO

While Tcl's never guaranteed anything about representations, it would be nice to not lose them.

ajpasadyn added on 2008-07-02 23:07:27:

File Added - 283441: tcllist.patch

Logged In: YES 
user_id=1055638
Originator: YES

It appears my mistake was not always passing at least 1 to NewListIntRep.  I've fixed that.  The reason it crashed was that the core is calling SetListFromAny with a null interp from several places.  I had copied the Tcl_SetObjResult call when NewListIntRep fails from the "from string rep" branch in the same routine, so it hadn't occurred to me it wasn't safe.
File Added: tcllist.patch

ajpasadyn added on 2008-07-02 23:02:33:

File Deleted - 283352:

ajpasadyn added on 2008-07-02 05:33:59:
Logged In: YES 
user_id=1055638
Originator: YES

OK there is definitely something wrong with that patch because I got a crash in clock format with it applied.  I'll look at it some more, but hopefully it's more obvious to someone here.

ajpasadyn added on 2008-07-02 03:54:39:

File Added - 283352: tcllist.patch

Logged In: YES 
user_id=1055638
Originator: YES

The attached patch seems to work for me, but I'd appreciate it if someone more familiar with this code could check it out.
File Added: tcllist.patch

ajpasadyn added on 2008-07-02 03:51:39:

File Added - 283351: jtest.tcl

Attachments: