Skip to content
Tcl Source Code History Of Ticket 8e666d7c956372d0
Login

History Of Ticket 8e666d7c956372d0

Artifacts Associated With Ticket 8e666d7c956372d0

  1. Ticket change [99a5c2cd51] (rid 222040) by kjnash on 2024-02-03 14:36:50:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      While investigating [fe4d7305a8], which has been fixed, I found another bug.
      
      ::history is a proc that calls the binary command ::tcl::history.  If ::history is renamed or deleted, the interpreter regenerates the proc ::history so that the immediate call of ::history to record the history does not fail.
      
      Ideally the user would be able to redefine proc ::history, to provide an alternative to the Tcl built-in command.  However, the attempt causes the interpreter to cease functioning, even if the new proc is identical to the old.  The interpreter appears to enter a tight CPU-consuming loop, while never reaching the point where it can accept another command.
      
    5. foundin initialized to: "8.6.13, 8.7"
    6. is_private initialized to: "0"
    7. login: "kjnash"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "a774b1f5653dc3360e29ea7d635a64e94c9f1dab"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "kjnash"
    14. subsystem initialized to: "19. [history]"
    15. title initialized to:
      Redefining proc ::history locks the interpreter into a tight loop
      
    16. type initialized to: "Bug"
  2. Ticket change [9b0edc8751] (rid 222042) by kjnash on 2024-02-03 17:18:58:

    1. comment changed to:
      While investigating [fe4d7305a8], which has been fixed, I found another bug.
      
      ::history is a proc that calls the namespace ensemble ::tcl::history whose components are procs ::tcl::Hist*.  All these commands are defined in file library/history.tcl, are listed (except ::tcl::history) in library/tclIndex, and are loaded on demand by the autoloader.
      
      File library/history.tcl also sets a trace on command ::history, so that if it is deleted, all the related commands ::tcl::* are deleted, and the array ::tcl::history that stores the command history is unset.
      
      If ::history is renamed or deleted, the autoloader reloads it when the next command is entered into the interactive interpreter.
      
      The user should be able to redefine proc ::history, to provide an alternative to the Tcl built-in command.  However, the attempt may cause the interpreter to cease functioning, notably when the new proc is identical to the old.  The interpreter enters a tight CPU-consuming loop, and never reaches the point where it can accept another command.
      
      What seems to be happening is that the tailcall in ::history attempts to evaluate "history" in namespace ::tcl, expecting to evaluate ::tcl::history, but because that command is absent it evaluates ::history instead, leading to infinite recursion.  A fix is:
      
      1. To list ::tcl::history in library/tclIndex
      
      2. To request ::tcl::history explicitly in the tailcall
      
      The fix is in the attached patch, which is listed below.
      
      Other matters:
      
      (a) Does the trace on ::history (deleting all dependencies ::tcl::*) serve any useful purpose, apart from saving memory?  I suggest removing it.
      
      (b) The interpreter usually catches infinite recursion.  In this case it does not.
      
      In view of the importance of ::history, I would appreciate review before committing this change.  If nobody objects I will also remove the trace mentioned above.
      
      
      diff -Naur original/library/history.tcl patched/library/history.tcl
      --- original/library/history.tcl        2024-01-18 17:18:18.000000000 +0000
      +++ patched/library/history.tcl 2024-02-03 16:53:40.144116588 +0000
      @@ -53,7 +53,7 @@
           }
       
           # Tricky stuff needed to make stack and errors come out right!
      -    tailcall apply {arglist {tailcall history {*}$arglist} ::tcl} $args
      +    tailcall apply {arglist {tailcall ::tcl::history {*}$arglist} ::tcl} $args
       }
       
      
       # (unnamed) --
      diff -Naur original/library/tclIndex patched/library/tclIndex
      --- original/library/tclIndex   2024-01-18 17:18:18.000000000 +0000
      +++ patched/library/tclIndex    2024-02-03 16:45:46.591373179 +0000
      @@ -20,6 +20,7 @@
       set auto_index(::auto_mkindex_parser::commandInit) [list source [file join $dir auto.tcl]]
       set auto_index(::auto_mkindex_parser::fullname) [list source [file join $dir auto.tcl]]
       set auto_index(history) [list source [file join $dir history.tcl]]
      +set auto_index(::tcl::history) [list source [file join $dir history.tcl]]
       set auto_index(::tcl::HistAdd) [list source [file join $dir history.tcl]]
       set auto_index(::tcl::HistKeep) [list source [file join $dir history.tcl]]
       set auto_index(::tcl::HistClear) [list source [file join $dir history.tcl]]
      
    2. login: "kjnash"
    3. mimetype: "text/plain"
    4. type changed to: "Patch"
  3. Add attachment "history-tclIndex-86.patch" [6bb42325e9] (rid 222044) by kjnash on 2024-02-03 17:19:20.

  4. Ticket change [bc9d57009f] (rid 222087) by jan.nijtmans on 2024-02-06 13:41:11:

    1. icomment:
      > If nobody objects I will also remove the trace mentioned above.
      
      It looks like this trace was added on purpose:
      [https://core.tcl-lang.org/tcl/info/3135d5681f5949c8]
      
      Therefore, I think removing it is a bad idea (but better ask @dkf, as he did this commit)
      
      Patch looks OK to me. Committed to a [https://core.tcl-lang.org/tcl/info/02f90739a1a4a3f6|branch] now.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  5. Ticket change [3dae0ee9ed] (rid 222129) by kjnash on 2024-02-07 12:09:53:

    1. icomment:
      (a) OK, let's keep the trace, it was just a bit confusing when trying to understand the bug!
      
      (b) A separate issue really.  Is it expected that the interpreter does not catch the infinite recursion in this case?
      
    2. login: "kjnash"
    3. mimetype: "text/plain"
  6. Ticket change [cfc2d914c3] (rid 222131) by jan.nijtmans on 2024-02-07 13:06:45:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2460348.04635587"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [3fe9d2e41913336b|here]. Thanks for the thorough analysis, and the patch!
      
      > (b) A separate issue really ....
      
      Yes, a separate issue. I have no idea whether the interpreter should/could catch this.
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"