Skip to content
Tcl Source Code Changes To Migrating scripts to Tcl 9
Login

Changes To Migrating scripts to Tcl 9

Changes to "Migrating scripts to Tcl 9" between 2024-04-12 09:38:01 and 2024-04-14 14:24:06

︙
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
















































177
178
179
180
181
182
183
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231







-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







The aim is to have a version for TCL8.7 and TCL9 in the same folder.

The names are as follows:

   *   tk87.dll -> tcl9tk87.dll (on Windows)
   *   libtk8.7.so -> libtcl9tk8.7.so (on UNIX)

A typical multi-version pckIndex.tcl file may look like this:
A typical multi-version pkgIndex.tcl file may look like this:

```
if {![package vsatisfies [package provide Tcl] 8.6-]} {
    return
}
if {[package vsatisfies [package provide Tcl] 9.0-]} {
    package ifneeded tdbc::odbc 1.1.6 \
	    "[list load [file join $dir tcl9tdbcodbc116.dll] [string totitle tdbcodbc]]"
} else {
    package ifneeded tdbc::odbc 1.1.6 \
	    "[list load [file join $dir tdbcodbc116.dll] [string totitle tdbcodbc]]"
}
```

See [TIP 595](https://core.tcl-lang.org/tips/doc/trunk/tip/595.md).

## Writing version and build-independent pkgIndex.tcl files

When writing `pkgIndex.tcl` files that are compatible with both
Tcl 8 and Tcl 9 as well as the autoconf and nmake build systems, the
following differences must be accounted for:

* Irrespective of the build system, Tcl 9 extension binaries are named differently
(prefixed with `tcl9`) from Tcl 8

* The initialization function name in Tcl 9 is case sensitive as noted previously.

* In Tcl 8, extension binaries built with the nmake system have a suffix attached.
For example, threaded builds have a `t` suffix attached while non-threaded builds
do not. The autotools based build system does not distinguish in this manner. This
inconsistency is not present in Tcl 9 but needs to be accounted for if the package
supports both Tcl versions and build systems.

The simplest way to achieve the above via the TEA build system is to write a
`pkgIndex.tcl.in` template for autoconf similar to the following:

```
package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ \
    [list apply [list {dir} {
        set packageInitName [string totitle @PACKAGE_NAME@]
        set path [file join $dir "@PKG_LIB_FILE@"]
        uplevel #0 [list load $path $packageInitName]
    }] $dir]
```

The `configure.ac` in the autotools build should contain the line

```
AC_CONFIG_FILES([Makefile pkgIndex.tcl])
```

The `makefile.vc` should contain the line

```
pkgindex: default-pkgindex-tea
```

This will result in both build systems generating a `pkgIndex.tcl`
that works for Tcl 8 as well as Tcl 9.





## Default encoding for scripts is UTF-8

The default encoding used when reading scripts, either with the `source`
command without an explicit `-encoding` option, or passed as a command
line argument to `tclsh` is utf-8 in Tcl 9 instead of the system
encoding as in Tcl 8.
︙