Menu

#1576 traces on array misbehaving

obsolete: 8.4a4
closed-fixed
46. Traces (50)
5
2004-03-28
2001-08-10
No

This shouldn't core-dump!

% info patch
8.4a4
% set x(bar) 0
0
% trace variable x r {set x(foo) 1 ;#}
% trace variable x r {unset -nocomplain x(bar) ;#}
% trace vinfo x
{r {unset -nocomplain x(bar) ;#}} {r {set x(foo) 1 ;#}}
% array get
x
": no such element in array
% array get x
Segmentation fault (core dumped)

Discussion

  • miguel sofer

    miguel sofer - 2001-08-10

    Logged In: YES
    user_id=148712

    Bug is also present in 8.3.3 and 8.0.5.

     
  • Don Porter

    Don Porter - 2001-08-10

    Logged In: YES
    user_id=80530

    Note, a very similar script causes a segfault
    in Tcl 8.3.3. (Change [unset -nocomplain ...]
    to [catch {unset ... )

     
  • miguel sofer

    miguel sofer - 2001-12-02

    patch to tclVar.c and trace.test

     
  • miguel sofer

    miguel sofer - 2001-12-02

    Logged In: YES
    user_id=148712

    It is difficult to define what the correct behaviour of
    [array get]
    should be when there are read traces that modify the array
    structure.

    In discussions on the Tcl'ers Chat with Kevin Kenny and
    Don Porter we agreed that a (the only ?) reasonable
    behaviour
    is given by

    proc array-get { aName } {
    set result [list]
    upvar 1 $aName array
    foreach s [array names array] {
    if { [info exists array($s)] } {
    # because a trace could have deleted it
    lappend result $s $array($s)
    }
    }
    return $result
    }

    The enclosed patch implements this behaviour and adds three
    tests
    for it. These tests cause illegal memory behaviour without
    the patch
    to tclVar.c - an access to a previously disposed Tcl_Obj is
    detected
    by TCL_MEM_DEBUG.

     
  • miguel sofer

    miguel sofer - 2001-12-05

    Logged In: YES
    user_id=148712

    Patch committed to HEAD.

     
  • miguel sofer

    miguel sofer - 2001-12-05
    • status: open --> closed-fixed
     
  • Don Porter

    Don Porter - 2001-12-05

    Logged In: YES
    user_id=80530

    the patch included no doc changes. Is there a
    best place to document the particular behavior?
    In the [array get] docs, perhaps?

     
  • miguel sofer

    miguel sofer - 2001-12-05
    • priority: 8 --> 3
    • status: closed-fixed --> open-fixed
     
  • miguel sofer

    miguel sofer - 2001-12-05

    Logged In: YES
    user_id=148712

    Re docs: or with [trace]? Or both?
    It is a really something that is relevant to the interplay
    between [array get] and [trace] - when there are read traces
    on an array that either add or remove an element of the
    array.

    I'm also not 100% happy with the error message when the
    trace unsets the whole array (see test trace-1.13 ): should
    it rather return {} and no error as does [array get
    nonExistingArray] ?

    Reopening the ticket, with lower priority now that the
    segfault is gone ...

     
  • Donal K. Fellows

    • labels: 104254 --> 46. Traces
     
  • Don Porter

    Don Porter - 2003-06-26
    • assigned_to: msofer --> dgp
     
  • Don Porter

    Don Porter - 2003-10-02
    • priority: 3 --> 8
     
  • Don Porter

    Don Porter - 2003-10-07
    • priority: 8 --> 5
     
  • Don Porter

    Don Porter - 2003-10-07
    • assigned_to: dgp --> msofer
     
  • Don Porter

    Don Porter - 2003-11-13
    • milestone: --> obsolete: 8.4a4
     
  • miguel sofer

    miguel sofer - 2004-03-28
    • summary: traces on array misbehaving --> traces on array misbehaving (doc)
     
  • miguel sofer

    miguel sofer - 2004-03-28

    Logged In: YES
    user_id=148712

    Docs added to array.n

     
  • miguel sofer

    miguel sofer - 2004-03-28
    • summary: traces on array misbehaving (doc) --> traces on array misbehaving
    • status: open-fixed --> closed-fixed