#4057 dict to list changes element representations

obsolete: 8.5.3
closed-fixed
7
2008-07-20
2008-07-01
No

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.

Discussion

  • Alexander James Pasadyn

    test script that reproduces the problem

     
  • Alexander James Pasadyn

    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

     
  • Alexander James Pasadyn

    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.

     
  • Alexander James Pasadyn

    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

     
  • Donal K. Fellows

    • assigned_to: nijtmans --> dkf
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902
    Originator: NO

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

     
  • Donal K. Fellows

    • milestone: --> obsolete: 8.5.3
    • priority: 5 --> 7
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902
    Originator: NO

    Fixed on HEAD. Backport needed.

     
  • Donal K. Fellows

    • status: open --> closed-fixed
     
  • Donal K. Fellows

    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.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks