Tcl Source Code

View Ticket
Login
Ticket UUID: 1331475
Title: [dict append] causes Tcl to crash
Type: Bug Created on: 2005-10-19 11:32:47
Submitter: aric_b Assigned to: msofer
Subsystem: 47. Bytecode Compiler Severity:
Priority: 5 Medium Last modified: 2005-10-19 20:15:51
Status: Closed Closed by: msofer
Resolution: Fixed Closed on: 2005-10-19 13:15:51
Version: obsolete: 8.5a4
Description:
[dict append], called as part of a particular sequence,
causes Tcl to crash.  The following code consistently
produces the error for me in ActiveState tclsh 8.5a4 on
Windows XP SP2:

    proc problem {list_of_lists} {

        set one 1
        set two 2

        foreach list $list_of_lists {
            if {[llength $list] > 1} {
                dict append a b c
            }
        }
    }

    set list_of_lists [list [list a b]]

    problem $list_of_lists

I noticed the following:

* The error occurs whether or not the dictionary and/or
key in question exist before the call to [dict append].

* All of the code in the proc seems to be necessary to
produce the error; for example, if either [set one 1]
or [set two 2] is absent, the error doesn't occur.

* The error doesn't seem to occur if there's a command
on the line immediately below the call to [dict
append], for example:

        ...
            if {[llength $list] > 1} {
                dict append a b c
                expr 5
            }
        ...
User Comments:
msofer added on 2005-10-19 20:15:51:
Logged In: YES 
user_id=148712

This was caused by a faulty peephole optimisation (peeping
at the wrong hole) in the INST_DICT_(L)APPEND opcode. 

Fixed in HEAD. Unluckily it is extremely  difficult to test
for this: it only fails if there happens to be a '1' at the
byte we are wrongly testing. This also means that it is a
difficult bug to trigger.