Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 3b2130975679516266863cf55976e91c5e8d5faf
Ticket: 219280ffffffffffffffffffffffffffffffffff
[unknown]: bad errorInfo management
User & Date: nobody on 2000-10-26 05:09:51
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 1907 Bug
    Version: 8.1b3
    SubmitDate: '1999-04-19'
    LastModified: '1999-04-21'
    Severity: MED
    Status: UnAssn
    Submitter: pat
    ChangedBy: redman
    OS: Other
    Machine: NA
    FixedDate: '2000-10-25'
    ClosedDate: '2000-10-25'
    
    
    Name:
    
    Don Porter
    
    
    CVS:
    
    $Id: init.tcl,v 1.29 1999/04/16 00:46:56 stanton Exp $
    
    
    Comments:
    
    After applying the patch:
    
    
        $ tclsh8.1 demo.tcl
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b {contrived example: rare circumstance 
    
                        where the point at which to prune the
    
                        error stack cannot be uniquely determined.
    
                        foo bar foo
    
        "..."
    
            ("uplevel" body line 1)
    
            invoked from within
    
        "uplevel 1 $args"
    
            (evaluating "unknown parray ...")
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        The submitted patch is an improvement on the existing code,
    
        but it still doesn't properly handle the last example in
    
        demo.tcl.  Hopefully the power of Open Source will produce
    
        the rest of the answer from someone else.
    
    
        The same bug exists in the 8.0.x sources, so this fix should
    
        be applied there too.
    
    
    ReproducibleScript:
    
    # FILE: demo.tcl
    
        #
    
        foreach arg {
    
                        c
    
                        {argument
    
                        which spans
    
                        multiple lines}
    
                        {argument which is all on one line but which is of such
    
        great length that the Tcl C library will truncate it when appending it
    
        onto the global error stack}
    
                        {argument which spans multiple lines
    
                        and is long enough to be truncated and
    
        "               <- includes a false lead in the prune point search
    
                        and must be longer still to force truncation}
    
                        {contrived example: rare circumstance 
    
                        where the point at which to prune the
    
                        error stack cannot be uniquely determined.
    
                        foo bar foo
    
        "}
    
                } {
    
            # Make auto-loader forget any past work
    
            auto_reset
    
            foreach i {1 2} {
    
                # First pass: [unknown] auto-loads [parray]
    
                # Second pass: [parray] already loaded
    
                catch {parray a b $arg}
    
                puts "STACK $i:\n---\n$errorInfo\n---"
    
            }
    
            puts ""
    
        }
    
    
    ObservedBehavior:
    
    $ tclsh8.1 demo.tcl
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b {argument
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b {argument which spans multiple lines
    
                        and is long enough to be truncated and
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
        STACK 1:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b {contrived example: rare circumstance 
    
                        where the point at which to prune the
    
                        error stack cannot be uniquely determined.
    
            invoked from within
    
        "parray a b $arg"
    
        ---
    
        STACK 2:
    
        ---
    
        called "parray" with too many arguments
    
            while executing
    
        "parray a b $arg"
    
        ---
    
    
    DesiredBehavior:
    
    The original code strips five lines from ::errorInfo to erase
    
        the evidence of the [uplevel] command.  From this I infer that
    
        the correct behavior for [unknown] is to make the fact that it
    
        was called invisible to the caller.  Then, all the examples in
    
        demo.tcl should have STACK 1 and STACK 2 identical to each
    
        other, so it cannot be detected by the caller's examination of
    
        $::errorInfo whether or not [unknown] was called.
    
    
        The problem with the original code is that [uplevel] does not
    
        always contribute exactly five lines to $::errorInfo.  In general
    
        it's far more complicated than that. :(
    
    
    Patch:
    
    Index: init.tcl
    
    ===================================================================
    
    RCS file: /cvsroot/tcl/library/init.tcl,v
    
    retrieving revision 1.29
    
    diff -c -r1.29 init.tcl
    
    *** init.tcl    1999/04/16 00:46:56     1.29
    
    --- init.tcl    1999/04/19 23:19:17
    
    ***************
    
    *** 195,208 ****
    
                set code [catch {uplevel 1 $args} msg]
    
                if {$code ==  1} {
    
                    #
    
    !               # Strip the last five lines off the error stack (they're
    
    !               # from the "uplevel" command).
    
                    #
    
    ! 
    
                    set new [split $errorInfo \n]
    
    !               set new [join [lrange $new 0 [expr {[llength $new] - 6}]] \n]
    
    !               return -code error -errorcode $errorCode \
    
    !                       -errorinfo $new $msg
    
                } else {
    
                    return -code $code $msg
    
                }
    
    --- 195,302 ----
    
                set code [catch {uplevel 1 $args} msg]
    
                if {$code ==  1} {
    
                    #
    
    !               # Strip off the error stack those lines generated by
    
    !               # the "uplevel" command.
    
                    #
    
    !               # 1. Remove the last 3 lines, which are:
    
    !               #           ("uplevel" body line 1)
    
    !               #           invoked from within
    
    !               #       "uplevel 1 $args"
    
    !               #
    
                    set new [split $errorInfo \n]
    
    !               set new [join [lrange $new 0 [expr {[llength $new] - 4}]] \n]
    
    !               #
    
    !               # 2. Remove the quoted (and possibly truncated) $args
    
    !               #    which was passed to [uplevel] from the error stack.
    
    !               #
    
    !               # First strip off trailing "
    
    !               regsub {"$} $new {} new
    
    !               # Trailing "..." indicates truncation
    
    !               if {![regsub {\.\.\.$} $new {} new]} {
    
    !                   #
    
    !                   # No truncation -> this is the easy case.
    
    !                   # $new ends with "\n\"$args", strip that away
    
    !                   #
    
    !                   set index [string last "\n\"$args" $new]
    
    !                   set new [string trimright [string range $new 0 $index]]
    
    !               } elseif {[string first \n $args] == -1} {
    
    !                   #
    
    !                   # $args contains no "\n" -> also easy.
    
    !                   # The quoted and truncated $args occupies the
    
    !                   # last line of $new.  Strip it off.
    
    !                   set index [string last "\n\"" $new]
    
    !                   set new [string trimright [string range $new 0 $index]]
    
    !               } else {
    
    !                   #
    
    !                   # The tricky case
    
    !                   # $new ends with truncation of "\n\"$args", like so:
    
    !                   #
    
    !                   # $new: ________\n"|_______|
    
    !                   #                  | ^^^^^ |
    
    !                   #                  | match |
    
    !                   #                  | vvvvv |
    
    !                   #           $args: |_______|____________
    
    !                   #                  ^
    
    !                   #                  |
    
    !                   # Need to find this/
    
    !                   # point in $new and delete from there to the end.
    
    !                   # Find all the candidates...
    
    !                   set lines [split $new \n]
    
    !                   set tailStart [expr {[llength $lines] - 1}]
    
    !                   set candidates {}
    
    !                   while {$tailStart >= 0} {
    
    !                       if {[string match {"*} [lindex $lines $tailStart]]} {
    
    !                           set tail [join [lrange $lines $tailStart end] \n]
    
    !                           if {[string first $tail \"$args] == 0} {
    
    !                               lappend candidates $tailStart
    
    !                           }
    
    !                       }
    
    !                       incr tailStart -1
    
    !                   }
    
    !                   if {[llength $candidates] == 1} {
    
    !                       #
    
    !                       # There was exactly one candidate, so that's the
    
    !                       # prune point.
    
    !                       #
    
    !                       set lastKeepLine [expr {[lindex $candidates 0] - 1}]
    
    !                       set new [join [lrange $lines 0 $lastKeepLine] \n]
    
    !                   } else {
    
    !                       #
    
    !                       # In rare circumstances, there can be multiple
    
    !                       # candidates, or if something changes in the way
    
    !                       # future releases of the Tcl C library build 
    
    !                       # $errorInfo, this code may fail to find any candidate.
    
    !                       # The safest thing to do in that circumstance is
    
    !                       # just give up trying to remove the evidence of the
    
    !                       # [uplevel] from the error stack and just pass the
    
    !                       # error stack on to the caller as it was passed to us.
    
    !                       #
    
    !                       # Anybody have a better idea?
    
    !                       #
    
    !                       append errorInfo \
    
    !                               "\n    (evaluating \"unknown $name ...\")"
    
    !                       return -code error -errorcode $errorCode \
    
    !                               -errorinfo $errorInfo $msg
    
    !                   }
    
    !               }
    
    !               #
    
    !               # 3. Remove the last remaining line, which is:
    
    !               #           while executing
    
    !               #    or some similar introductory phrase.
    
    !               #
    
    !               set index [string last \n $new]
    
    !               set new [string trimright [string range $new 0 $index]]
    
    !               #
    
    !               # 4. Guarantee that proper introductory phrase is appended.
    
    !               #       When ($new == $msg)     ==> "    while executing"
    
    !               #       Otherwise               ==> "    invoked from within"
    
    !               #
    
    !               if {[string compare $new $msg] == 0} {
    
    !                   return -code error -errorcode $errorCode $msg
    
    !               } else {
    
    !                   return -code error -errorcode $errorCode \
    
    !                           -errorinfo $new $msg
    
    !               }
    
                } else {
    
                    return -code $code $msg
    
                }
    
    
    PatchFiles:
    
    init.tcl
    
    
    
    
    4/22/99 - redman - A little late for 8.1.0, need to verify that this is a bug and not an RFE.  Hold off until 8.1.1.
    
    
    
  4. foundin changed to: "obsolete: 8.1b3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "56. LibTomMath"
  10. title changed to: "[unknown]: bad errorInfo management"
  11. type changed to: "Bug"