Repository navigation
Tcl9 compatibility.
Details below.
What's Changed
Full Changelog: v8.6.3...v9.0.0
Details
Update TclX for Tcl 9 API compatibility (#27) (#28)
-
Update TclX for Tcl 9 API compatibility (#27)
-
Update TclX for Tcl 9 API compatibility
The current TclX implementation depends on several Tcl 8-era
APIs and compatibility assumptions that no longer hold with Tcl
9. This commit updates TclX for Tcl 9 API compatibility,
allowing it to build, load, and pass the main test suite
against Tcl 9.1.
- Update CI to build against Tcl 9.1a1
Build Tcl 9.1a1 from the core-9-1-a1 branch in Linux and macOS
GitHub Actions instead of using Tcl 8.6.
The workflows now clone the Tcl source branch, build and
install Tcl during CI, locate the installed tclConfig.sh and
tclsh paths dynamically, verify the Tcl patchlevel, and pass
the discovered Tcl configuration directory to configure.
- Remove obsolete Ubuntu toolchain PPA
Stop adding ppa:ubuntu-toolchain-r/test in the Linux CI
workflow.
Ubuntu Noble provides gcc-11 and g++-11 through the standard
repositories, so the external PPA is unnecessary and can cause
CI failures when Launchpad is unreachable.
- Tighten Tcl version checks in CI
Add stricter Tcl version validation to the Linux and macOS CI
workflows.
The workflows now source the discovered tclConfig.sh, combine
TCL_VERSION and TCL_PATCH_LEVEL to verify the expected Tcl
9.1a1 version, and keep the tclsh patchlevel check using
EXPECTED_TCL_VERSION. This ensures CI does not accidentally
configure against a different Tcl installation.
The workflow YAML files were also formatted with yamlfmt.
- Use checked-in configure on macOS
The macOS GitHub Actions runner does not provide autoreconf by
default, which caused the Mac CI configure step to fail before
the build started.
Since the generated configure script is checked in again, run
it directly instead of regenerating it in CI.
- Remove unused Tcl 9 compatibility helpers
Drop unused helper functions added for Tcl 9 compatibility in
the chmod, list, and string command implementations.
The list and string commands already use the existing TclX
index parsing paths where needed, preserving TclX arithmetic
index expression semantics. The chmod mode parser was also
unused, so keeping it only required compiler-specific unused
annotations without changing behavior.
This removes dead code and avoids carrying compatibility
wrappers that have no callers.
- Use Tcl_Size for Tcl string lengths
Tcl 9 uses Tcl_Size for string lengths returned by Tcl object
APIs, so local variables and helper parameters that receive
those lengths should use Tcl_Size as well.
Update the TclX_EchoObjCmd length variable and the string helper
input-length parameters, while keeping ExpandString's existing
int output-length interface for its callers.
- Add strict CI smoke test for built TclX library
Add a smoke test step to the Linux and macOS CI workflows after
the build step and before the full test suite.
The smoke test loads TclX from the build directory via
TCLLIBPATH and sets TCLX_LIBRARY so the extension can find the
TclX script library before installation. It verifies the
package and runtime versions, prints the loaded shared library,
and asserts results from a small set of TclX string commands.
This gives CI an early hard failure if the built TclX library
cannot be loaded or basic commands return unexpected results,
even where the broader test suite is allowed to continue on
error.
- Avoid internal int object conversion in dup
Use Tcl_GetIntFromObj when parsing numeric dup arguments as
file descriptors instead of converting through
Tcl_GetObjType("int").
Tcl object type names are internal details and
Tcl_GetObjType("int") is not a safe public conversion path.
Under Tcl 9 this can return NULL, causing Tcl_ConvertToType to
segfault when dup handles an invalid numeric file descriptor
such as dup 100.
Using Tcl_GetIntFromObj avoids that internal type lookup and
lets the invalid file descriptor path report the expected POSIX
EBADF error.
Keep the existing channel-first lookup so numeric-looking
channel names are not mistaken for file descriptors.
- Support Tcl 9 profile command dispatch
Tcl 9 can dispatch commands through Tcl_ObjCmdProc2 when
isNativeObjectProc is 2. Add a Tcl 9 wrapper for that entry
point and install it when the profiler temporarily rewrites
command information.
Restore the exact Tcl_CmdInfo captured by the trace callback
before dispatching the original command. Restoring selected
fields can leave a mixed wrapper/original command state when
newer Tcl versions add command dispatch fields.
Initialize the replacement Tcl_CmdInfo from the saved command
info before modifying it, so Tcl_SetCommandInfoFromToken
receives fully initialized version-specific fields.
Use Tcl_GetString for the tailcall check instead of inspecting
Tcl_Obj internals directly.
- Detect profiled Tcl procedures by delete hook
Under Tcl 9, command dispatch may use native object wrappers
and Tcl_ObjCmdProc2, so objProc and objClientData are not
reliable indicators of whether a command is a Tcl procedure.
Looking the command up again by name is also unnecessary
because the trace callback already provides the command token
and saved command info.
Use TclProcDeleteProc as the Tcl procedure marker. This
preserves ordinary proc-only profiling while avoiding native
commands such as join in proc-only mode.
- Update profile stack expectations for Tcl 9
Tcl 9 command dispatch does not produce the same uplevel stack
entries in the profile-3.2 and profile-3.4 cases. Keep the
existing Tcl 8 expectations and add Tcl 9-specific expected
result lists.
The profiler behavior now matches the Tcl 9 command dispatch
model while preserving the old Tcl 8 expectations.
- Use Tcl package version checks in profile tests
Use package vsatisfies with the provided Tcl package version
when selecting Tcl 9 profile expectations.
This avoids numeric comparison of tcl_version and keeps the
test branch selection aligned with Tcl package version
semantics while remaining compatible with Tcl 8.6 and Tcl 9.
- Add Tcl_Size compatibility for Tcl 8.6 builds
Tcl_Size and TCL_SIZE_MODIFIER are provided by Tcl 9, but this
branch also needs to build against Tcl 8.6. Add a small
compatibility shim that maps Tcl_Size to int for Tcl 8.6 and
defines an empty printf modifier.
This lets Tcl 9-oriented size cleanups compile with Tcl 8.6
while using the native Tcl_Size definitions when building
against Tcl 9.
- Handle Tcl 8.6 regexp error text in lmatch test
Tcl 8.6 and Tcl 9 report the invalid regexp pattern in
lmatch-2.3 with different diagnostic text. Select the expected
message using Tcl package version checks so the test passes
with both Tcl 8.6 and Tcl 9.
- Require Tclx matching Tcl version in tests
The TclX package version now follows the Tcl major/minor
version used for the build. Tests that hard-code Tclx 8.4 or
Tclx 8.6 therefore fail or abort when the package is built
against Tcl 9.x and provides Tclx 9.x.
Derive the required Tclx major/minor version from the running
Tcl interpreter in all.tcl, testlib.tcl, and arrayproc.test.
This preserves the existing Tcl 8.6 behavior while allowing the
same test suite to run against Tcl 9.x builds.
- Track build Tcl version in TclX package version
TclX post-4 package versions are intended to track the Tcl
version used for the build. Major and minor versions follow
Tcl's major and minor version, and the patch level follows
Tcl's patch level where possible.
Derive PACKAGE_VERSION from TCL_VERSION after loading
tclConfig.sh so the generated package version, shared library
suffix, pkgIndex.tcl entry, and Tcl_PkgProvide version all use
the detected Tcl major/minor version.
Derive FULL_VERSION from TCL_VERSION and TCL_PATCH_LEVEL so
infox version and the tcl_findLibrary lookup reflect the build
Tcl patch level where it is available.
This keeps Tcl 8.6 builds providing Tclx 8.6 with an 8.6.x full
version, while Tcl 9.x builds provide the matching Tclx 9.x
package and full version.
-
Remove redundant zero flag from lvar assignment
-
Use TCL_SIZE_MODIFIER for the call frame level in cmdtrace
The interpreter's call frame level is int in some Tcl builds
and Tcl_Size in others, so a hardcoded %d or %ld warns on
whichever build has the other type. Format it with
TCL_SIZE_MODIFIER and cast the value to Tcl_Size so the
specifier and the argument always agree.
- Use switch in place of the removed case command
Tcl 9 no longer provides case, and its compatibility
replacement does not support the syntax used by these tests. As
a result, the file scan tests stopped early without reporting a
failure.
Replace the three remaining uses with switch, using exact
matching since none of the patterns contain wildcards.
- Drop the case compatibility command
Nothing in TclX uses case anymore, and Tcl 9 has removed it in
favour of switch. The compatibility command does not reproduce
case's syntax or matching rules, so leaving it absent avoids
silently taking the wrong branch.
- Take the expected regexp error text from the interpreter
Tcl 9 reworded the regular expression compilation error.
scanmatch passes that message through unchanged, so ask the
interpreter for it rather than hard coding one version's
wording.
- Keep a usable copy of auto_reset in the library tests
auto_reset deletes every command listed in the autoload index,
including itself, and these tests then point auto_path at
directories it cannot be reloaded from. The first reset
therefore left the file unable to reset again, and it stopped
partway through on every Tcl version.
- Mark the failing library index tests as known bugs
These tests fail identically under Tcl 8.6 and Tcl 9 and were
never reached before, because the file stopped early on the
first reset. They cover package index handling, not Tcl version
compatibility.
- Report a test file that stops early as a failure
The test runner caught errors raised while sourcing a test file
but only printed the message, so tests below the error were
never counted and the run finished reporting success. Count
those errors towards the exit status and print the error stack
with them.
- Release the result of the index expression
Tcl hands back a result object from expression evaluation that
the caller owns. It was never released, so every index
expression leaked one object.
- Match the profile tests to the Tcl 9.0 and 9.1 releases
Tcl 9.1 is the first to compile uplevel into bytecode and the
profiler does not trace compiled commands. profile-3.2 and
profile-3.4 failed on Tcl 9.0, which still runs it as a
command. Choose the expectations without uplevel from 9.1 on.
tcltest 2.6 in Tcl 9.1.0 runs each test body from
tcltest::TestOnce. The stack filter matched Eval and RunTest
only with their leading colons and the profiler records
TestOnce without them. Match all three with or without the
colons.
- Indent the cmdtrace test traces by their level numbers
cmdtrace prints the real level of each command but stops
indenting at level 20. Test bodies run two levels deeper under
tcltest 2.6 in Tcl 9.1.0. The body of the if in DoStuff then
reached level 21 and cmdtrace printed it at the same depth as
the if.
- Qualify the globals used when setting up the TclX library
tclx.tcl read tclx_library and set auto_index and auto_path by
their plain names inside namespace eval. Tcl 9 no longer
resolves such names to existing globals. The check for
tclx_library failed and the setup never ran. buildpackageindex
could not be autoloaded and the library directory never reached
auto_path.
- Build CI against the released Tcl 8.6, 9.0 and 9.1
CI built only Tcl 9.1a1, where the tests that failed on the
9.0.4 and 9.1.0 releases passed. Tcl 8.6 and 9.0 went untested.
Pick tclsh by the version tclConfig.sh reports, which also
finds tclsh8.6.
tclsh reads the smoke test from a here document in the system
encoding. In a C locale the accented letter in the clength
check would count as two characters. Use the escape \u00e9
there instead.
- Run CI for pull requests into any branch
Both workflows ran only for pull requests into master. Tcl 9
work goes into BCK-13016-tcl9-upgrade.
- Remove pregenerated configure and require autoconf, update the Mac CI to match.
Co-authored-by: Zoltán Kéri zolk3ri@protonmail.com