@@ -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
5953end
6862
6963tcl_result () = tcl_result (tcl_interp[])
7064function 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 ))
7367end
7468
7569function tcl_evalfile (name)
8377tcl_eval (cmd) = tcl_eval (cmd,tcl_interp[])
8478function 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
156154end
0 commit comments