Tcl Source Code

View Ticket
Login
Ticket UUID: 2907095
Title: library/init.tcl using wrong string comparison
Type: Bug Version: None
Submitter: wjc Created on: 2009-12-01 20:23:05
Subsystem: 38. Init - Library - Autoload Assigned To: dgp
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-12-02 23:06:32
Resolution: Invalid Closed By: dgp
    Closed on: 2009-12-02 02:38:34
Description:
Minor nit: library/init.tcl is checking for package with;

if {[info commands package] == ""}

instead of

if {[info commands package] eq ""}

This works, but we should probably follow the advice in expr.n in the library code for clarity.

(only reason I noticed is because I am trying to execute this with a version of partcl that is (wrongly) treating == as always numeric.)

inlined diff (against old version) below.
---
diff --git a/library/init.tcl b/library/init.tcl
index 6b92c58..1ba39a6 100644
--- a/library/init.tcl
+++ b/library/init.tcl
@@ -14,7 +14,7 @@
 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 #

-if {[info commands package] == ""} {
+if {[info commands package] eq ""} {
     error "version mismatch: library\nscripts expect Tcl version 7.5b1 or later
 }
 package require -exact Tcl 8.5.6
User Comments: andreas_kupries added on 2009-12-02 23:06:32:
Ok. I see your point Don.
We need a command which has existed at least since 7.4, better if it existed earlier.
Based on the above 'eq' is certainly unsuitable.
The attached patch however used [llength], not the originally proposed 'eq', and this command should have the necessary characteristic, i.e. IIRC it was present in 7.3, likely even before.

Of course, if deleting the block in init.tcl is ok, doing that should be trivial.
Note that the patch also touches tcltest.tcl.

dgp added on 2009-12-02 09:38:34:

allow_comments - 1


You have both missed the point.  Those lines
of init.tcl are present to protect the rest of
the script against getting [source]d by a Tcl
interp of version 7.4 (!!) or earlier.  If you change
it to anything that isn't in Tcl 7.4 you defeat
whatever purpose it has.

The proper way to update those lines to the
expectations of modern Tcl is to simply
delete them, on the theory that Tcl 7.4 no
longer exists, and [package] is present
everywhere Tcl is, just like [set].  I don't mind
a commit that does exactly that.

andreas_kupries added on 2009-12-02 05:31:20:

File Added - 353482: info-commands.patch

andreas_kupries added on 2009-12-02 05:30:40:
Attached a patch fixing the nit, and similar ones in tcltest.tcl.
Assigned to tcltest maintainer for review.

andreas_kupries added on 2009-12-02 03:25:28:
[12:18]aku[info commands package] == "" -- Actually eq is not really right either. info command's result is a list, so we should use '![llength [info commands package]]'.

Attachments: