home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / tcl / 1359 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.7 KB  |  67 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!mdisea!kelsey
  3. From: kelsey@mdd.comm.mot.com (Joe Kelsey)
  4. Subject: Bug in extended Tcl: LoadPackageIndexes
  5. Message-ID: <1992Sep15.221703.18160@mdd.comm.mot.com>
  6. Summary: Loads *last* package in a path instead of *first* package in a path.
  7. Keywords: TCLPATH auto_path TCLSH LoadPackageIndexes demand_load
  8. Sender: news@mdd.comm.mot.com
  9. Organization: Motorola, Mobile Data Division - Seattle, WA
  10. Date: Tue, 15 Sep 1992 22:17:03 GMT
  11. Lines: 54
  12.  
  13. Extended TCL searches through the TCLPATH looking for files named *.tlib.
  14. Whenever it finds one, it loads the package index.  At the end of this
  15. process, it then looks for defined procs.  If you use TCLPATH, expecting it to
  16. operate like PATH, with an earlier instance of a name superseding a later
  17. instance of a name, you can expect surprises!  The problem occurs if you try
  18. to test a new package by placing it in a directory path in front of the
  19. standard path, for example, 
  20.  
  21. set TCLPATH {../local /usr/local/lib/tcl /usr/local/lib/tk}
  22.  
  23. Then place test.tlib in ../local, with the ``official'' version in
  24. /usr/local/lib/tcl.  The TCLSH:LoadPackageIndexes command uses the full
  25. pathname to determine if it already loaded a package instead of the last file
  26. name, thus resulting in the last package encountered becoming the loaded
  27. package!  I think the problem occurred because the ``Ouster'' style indexing
  28. allows only one index per directory, while the extended package concept places
  29. an index per package library file.
  30.  
  31. I fixed the problem by changing the TCLENV(LOADED:xxx) array element to
  32. mention just the package name rather than the full path name:
  33.  
  34. *** extended/tcllib/TclInit.tcl.orig    Sat Aug 22 09:26:56 1992
  35. --- extended/tcllib/TclInit.tcl    Tue Sep 15 13:22:14 1992
  36. ***************
  37. *** 58,69 ****
  38.   # Load library indexes along path.
  39.   #
  40.   proc TCLSH:LoadPackageIndexes {path} {
  41. !     global TCLPATH TCLENV
  42.       foreach dir $path {
  43.           foreach libFile [glob -nocomplain $dir/*.tlib] {
  44. !             if ![info exists TCLENV(LOADED:$libFile)] {
  45.                   loadlibindex $libFile
  46. !                 set TCLENV(LOADED:$libFile) 1
  47.               }
  48.           }
  49.           if {[file readable $dir/tclIndex] && ![info exists TCLENV(LOADED:$dir/tclIndex)]} {
  50. --- 58,70 ----
  51.   # Load library indexes along path.
  52.   #
  53.   proc TCLSH:LoadPackageIndexes {path} {
  54. !     global TCLENV
  55.       foreach dir $path {
  56.           foreach libFile [glob -nocomplain $dir/*.tlib] {
  57. !         set libName [string range $libFile [expr [string last / $libFile]+1] end]
  58. !             if ![info exists TCLENV(LOADED:$libName)] {
  59.                   loadlibindex $libFile
  60. !                 set TCLENV(LOADED:$libName) 1
  61.               }
  62.           }
  63.           if {[file readable $dir/tclIndex] && ![info exists TCLENV(LOADED:$dir/tclIndex)]} {
  64.  
  65. /Joe
  66.  
  67.