Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0a165629c83abdb1c9f53e80e976c6b50fcecbb9
Ticket: 1ae12987cb21ae25cdb699d9c41d2596d8bd0035
Clean up history (::tcl::history) before/on exit (i.e., before exit handlers)
User & Date: mr_calvin on 2016-10-21 14:37:03
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    The internal event storage of ::history (::tcl::history array) is not explicitly cleared when exiting (master interp, Tcl_Exit). Extensions' exit handlers, therefore, potentially see unbalanced refcounts on Tcl_Objs referenced from ::tcl::history.
    
    See for an example http://paste.tclers.tk/3973.
    
    Possible action items:
    - call [::history::clear] on Tcl_Exit (not only for interp teardown).
    - have [rename ::history {}] run the cleanup.
    
    Excerpt from the IRC discussion with dgp and dkf ():
    
    mr_calvin: (my main question basically is: why is an interactive tclsh not cleaning up the ::tcl::history at some early point during exit, before the exit handlers kick in.)
    
    <dgp> IIRC, [history] is coded mostly (entirely?) in Tcl?
    
    <dgp> And Tcl lacks good interface to exit handling.
    
    mr_calvin: yeah … library/history.tcl
    
    <dkf> Could just make Tcl_Main call [history clear] on the way out?
    
    <dgp> no
    
    <dkf> as handling all cases *very* hard
    
    <dgp> this cleanup would normally be handled by interp teardown
    
    <dgp> ....that [exit] does not tear down interps.
    
    <dkf> if you have something that needs to be freed, you need an exit handler and those REQUIRE the C API to set up
    
    dkf: as I wrote a little earlier. we do internal bookkeeping on Tcl_Objs intreps in NSF/NX, on exit, we draw the balance (exit handler) and references from tcl::history show up as unbalanced refcounts.
    
    <dkf> but effectively we *know* there are references retained unless you finalize
    
    mr_calvin: but doing a “unset -nocomplain ::tcl::history” in our exit handler would be one option (at least in our memdebug build) to balance those refcounts in time, wouldn’t it?
    
    <dkf> [::history clear] would leave me happier 
    
    <dgp> Does [rename history {}] do a cleanup?
    
    <dkf> probably not
    
    <dgp> that would be a bug worth fixing.
    
  5. foundin changed to: "core-8-6-branch"
  6. is_private changed to: "0"
  7. login: "mr_calvin"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "d4d1d8192a46acf2c7d58cddc1040ecdbc9c9d77"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "mr_calvin"
  14. subsystem changed to: "19. [history]"
  15. title changed to:
    Clean up history (::tcl::history) before/on exit (i.e., before exit handlers)
    
  16. type changed to: "Bug"