Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b800b447acdd7c00678eb62b33205e1b1fa6516c
Ticket: 1162286fffffffffffffffffffffffffffffffff
Inconsistent Tcl_PkgRequire return values
User & Date: hemanglavana on 2005-03-13 03:59:28
Changes

  1. assignee changed to: "dgp"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Hi,
    
    The documentation for "package" command recommends that
    "package provide <pkg> <ver>" should be at the bottom
    of the library. However, most users are not aware of
    the problem that can occur if the "package provide" cmd
    is at the top of the library. This is illustrated in
    the following example:
    
    hlavana-u5:138> cat foo.tcl 
    # foo.tcl
    package provide foo 0.9.1
    proc foo args {puts "PRINT: foo"}
    set a ;# syntax error: var a is not defined
    hlavana-u5:139>
    hlavana-u5:139> cat pkgIndex.tcl 
    # pkgIndex.tcl
    package ifneeded foo 0.9.1 [list source [file join $dir
    foo.tcl]]
    hlavana-u5:140>
    hlavana-u5:140> cat run_foo.tcl 
    # run_foo.tcl
    catch {package require foo} out1
    puts "First time=$out1"
    catch {package require foo} out2
    puts "Second time=$out2"
    hlavana-u5:141>
    hlavana-u5:141> tclsh run_foo.tcl 
    First time=can't read "a": no such variable
    Second time=0.9.1
    hlavana-u5:142>
    
    This example shows that a script might end up thinking
    that the package foo has been loaded successfully even
    though  there were errors in loading it.
    
    Moreover, most users like to see the "package provide
    .." command appear at the top of the library even after
    I have explained this issue to them. Note that many of
    the packages in tcllib module have the "package
    provide" command at the top of the script.
    
    To overcome these problems, I would like to request an
    enhancement: whenever "package require ..." fails to
    load correctly, it should internally invoke "package
    forget <pkg>". 
    
    This specific solution does have one side-effect
    though: consider that package foo, version 0.9 has been
    successfully loaded  and the script is trying to load
    package foo, version 1.1. If foo1.1 is not found, then
    blindly calling "package forget foo" will
    unload(forget) foo0.9 as well which is not correct.
    
    I hope this issue can be resolved in the tcl-core
    instead of asking users to move "package provide"
    command to the bottom of the library.
    
    Hemang.
    
    
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "hemanglavana"
  9. subsystem changed to: ""
  10. title changed to: "RFE: invoke "package forget <pkg>" on errors"
  11. type changed to: "Bug"