Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-12-02
23:06 • Ticket [2907095fff] library/init.tcl using wrong string comparison status st... artifact: dc75f62021 user: andreas_kupries
09:38 • Closed ticket [2907095fff]. artifact: 8b26ae8d75 user: dgp
05:31 • Ticket [2907095fff]: 4 changes artifact: 92e728e2d8 user: andreas_kupries
05:31 • Add attachment info-commands.patch to ticket [2907095fffffffff|2907095f... artifact: 8cbf5fb713 user: andreas_kupries
05:30 • Ticket [2907095fff] library/init.tcl using wrong string comparison status st... artifact: 5518fbeb06 user: andreas_kupries
03:25 • Ticket [2907095fff]: 4 changes artifact: 9b719030db user: andreas_kupries
2009-12-01
20:23 • New ticket [2907095fff]. artifact: 9675cf8756 user: wjc

library/init.tcl using wrong string comparison

Closed / Invalid2907095fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-12-01 20:23:05
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
andreas_kupriesplain2009-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]]'.
andreas_kupriesplain2009-12-02 05:30:40
Attached a patch fixing the nit, and similar ones in tcltest.tcl.
Assigned to tcltest maintainer for review.
andreas_kupriesplain2009-12-02 05:31:20
File Added - 353482: info-commands.patch
dgpplain2009-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_kupriesplain2009-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.
Log in (anonymous is fine) to add a comment.

Attachments: