Skip to content
Tcl Source Code History Of Ticket 219280
Login

History Of Ticket 219280

Artifacts Associated With Ticket 219280

  1. Ticket change [3b21309756] (rid 112673) by nobody on 2000-10-26 05:09:51:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized 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 initialized to: "obsolete: 8.1b3"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "56. LibTomMath"
    10. title initialized to: "[unknown]: bad errorInfo management"
    11. type initialized to: "Bug"
  2. Ticket change [a5000b6406] (rid 110299) by dgp on 2001-02-02 04:24:47:

    1. foundin changed to: "obsolete: 8.4a2"
    2. icomment:
      Registered patch as #103551
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. subsystem changed to: "38. Init - Library - Autoload"
    6. username: "dgp"
  3. Ticket change [400822755f] (rid 121558) by dgp on 2001-02-08 13:27:59:

    1. assignee changed to: "dgp"
  4. Ticket change [7783570034] (rid 89786) by dgp on 2001-04-07 01:00:07:

    1. status changed to: "Closed"
  5. Ticket change [2c0573f7e4] (rid 118836) by dgp on 2001-04-07 01:00:09:

    1. closedate changed to: "2001-04-06T18:00:09"
    2. closer changed to: "dgp"
    3. icomment:
      Logged In: YES 
      user_id=80530
      
      Fixed with patch 403551
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. username: "dgp"