Skip to content

Commit 65aa424

Browse files
authored
Merge pull request #161 from JuliaGraphics/vs/tk-9
Update to Tcl/Tk v9
2 parents 86eaf0b + 1256a49 commit 65aa424

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Tk_jll = "056b5f69-f28f-5060-ad8a-df43647a2b5c"
1515
[compat]
1616
Cairo = "1"
1717
Graphics = "1"
18-
Tcl_jll = "8.6"
19-
Tk_jll = "8.6"
20-
julia = "1.3"
18+
Tcl_jll = "9"
19+
Tk_jll = "9"
20+
julia = "1.6"

src/tkwidget.jl

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,22 @@ function init()
3232
ccall((:g_type_init,Cairo.libgobject),Cvoid,())
3333
tclinterp = ccall((:Tcl_CreateInterp,libtcl), Ptr{Cvoid}, ())
3434

35-
libpath = IOBuffer()
36-
print(libpath,"set env(TCL_LIBRARY) [subst -nocommands -novariables {")
37-
escape_string(libpath, joinpath(dirname(dirname(Tcl_jll.libtcl_path)), "lib", "tcl8.6"), "{}")
38-
print(libpath,"}]")
39-
tcl_eval(String(take!(libpath)),tclinterp)
40-
print(libpath,"set env(TK_LIBRARY) [subst -nocommands -novariables {")
41-
escape_string(libpath, joinpath(dirname(dirname(Tk_jll.libtk_path)), "lib", "tk8.6"), "{}")
42-
print(libpath,"}]")
43-
tcl_eval(String(take!(libpath)),tclinterp)
44-
45-
4635
if ccall((:Tcl_Init,libtcl), Int32, (Ptr{Cvoid},), tclinterp) == TCL_ERROR
4736
throw(TclError(string("error initializing Tcl: ", tcl_result(tclinterp))))
4837
end
38+
# In Tcl/Tk 9, library scripts are embedded in the .so via zipfs.
39+
# Tcl mounts its own zipfs automatically, but we must mount Tk's.
40+
if ccall((:TclZipfs_Mount,libtcl), Int32,
41+
(Ptr{Cvoid}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}),
42+
tclinterp, Tk_jll.libtk_path, "//zipfs:/lib/tk", C_NULL) == TCL_ERROR
43+
throw(TclError(string("error mounting Tk zipfs: ", tcl_result(tclinterp))))
44+
end
4945
if ccall((:Tk_Init,libtk), Int32, (Ptr{Cvoid},), tclinterp) == TCL_ERROR
5046
throw(TclError(string("error initializing Tk: ", tcl_result(tclinterp))))
5147
end
5248
global timeout
53-
@static if VERSION >= v"0.7.0-DEV.3526"
49+
if ccall(:jl_generating_output, Cint, ()) != 1
5450
timeout = Timer(tcl_doevent, 0.1, interval=0.01)
55-
else
56-
timeout = Timer(tcl_doevent, 0.1, 0.01)
5751
end
5852
tclinterp
5953
end
@@ -68,8 +62,8 @@ end
6862

6963
tcl_result() = tcl_result(tcl_interp[])
7064
function tcl_result(tclinterp)
71-
unsafe_string(ccall((:Tcl_GetStringResult,libtcl),
72-
Ptr{UInt8}, (Ptr{Cvoid},), tclinterp))
65+
objPtr = ccall((:Tcl_GetObjResult,libtcl), Ptr{Cvoid}, (Ptr{Cvoid},), tclinterp)
66+
unsafe_string(ccall((:Tcl_GetString,libtcl), Ptr{UInt8}, (Ptr{Cvoid},), objPtr))
7367
end
7468

7569
function tcl_evalfile(name)
@@ -83,8 +77,8 @@ end
8377
tcl_eval(cmd) = tcl_eval(cmd,tcl_interp[])
8478
function tcl_eval(cmd,tclinterp)
8579
#@show cmd
86-
code = ccall((:Tcl_Eval,libtcl), Int32, (Ptr{Cvoid}, Ptr{UInt8}),
87-
tclinterp, cmd)
80+
code = ccall((:Tcl_EvalEx,libtcl), Int32, (Ptr{Cvoid}, Ptr{UInt8}, Int, Int32),
81+
tclinterp, cmd, -1, 0)
8882
result = tcl_result(tclinterp)
8983
if code != 0
9084
throw(TclError(result))
@@ -146,11 +140,15 @@ function jl_tcl_callback(fptr, interp, argc::Int32, argv::Ptr{Ptr{UInt8}})::Int3
146140
return TCL_ERROR
147141
end
148142
if isa(result,String)
149-
ccall((:Tcl_SetResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, Int32),
150-
interp, result, TCL_VOLATILE)
143+
obj = ccall((:Tcl_NewStringObj,libtcl), Ptr{Cvoid}, (Ptr{UInt8}, Int32),
144+
result, -1)
145+
ccall((:Tcl_SetObjResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}),
146+
interp, obj)
151147
else
152-
ccall((:Tcl_SetResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, Int32),
153-
interp, empty_str, TCL_STATIC)
148+
obj = ccall((:Tcl_NewStringObj,libtcl), Ptr{Cvoid}, (Ptr{UInt8}, Int32),
149+
empty_str, 0)
150+
ccall((:Tcl_SetObjResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}),
151+
interp, obj)
154152
end
155153
return TCL_OK
156154
end

0 commit comments

Comments
 (0)