Hi all!
I have the following code snippet:
···
…
h=Hash.new
(0…4).each {|c|
(0…9).each {|r|
h["#{r},#{c}"]="#{r} ; #{c}";
}
}
v=TkVariable.new(h)
#~ puts "before: #{v.value}"
puts "ok."
t2=TkTable.new() {
rows 10
cols 5
variable v
}
t2.pack()
Tk.mainloop()
(TkTable is a wrapper for a tktable tcl widget written by me. It uses
’variable’ to store the data of the table cells.)
This works perfectly, just as I expect. BUT, if I comment out the
debugging puts(), then it prints v’s content, then ‘ok.’ just as before,
but after that the program hangs, the X window do not appear, and I
cannot even stop the program with CTRL-C! If I simply just read the
v.value (do not print it), the result is similar.
With v.inspect the
problem do not occur. What difference makes reading a TkVariable’s
value???
My second question is related to the previous: I have the feeling that
this ‘hang’ really means a runtime error in the ruby code which is
executed from tcl (which is executed from ruby :). So, my question is
how to receive these error messages, and why do the process hang if it
encounters with an error like this?
Hello,
I have simplified the problem. Here is the testprogram:
···
#!/usr/bin/env ruby
require ‘tk.rb’
begin
Tk::INTERP._eval(‘bad_cmd_name xxsx’)
rescue
end
puts "before mainloop"
Tk.mainloop
It prints out ‘before mainloop’, but do not creates its X form, and
cannot be interrupted by ctrl-c. Tested with 1.6.8 and 1.8.0. (Anyway,
TkVariable::result generates a (catched) error when the tcl variable is
an array, that’s why the program in my previous posting encountered this
problem.)
If the _eval cmd is replaced to
Tk.tk_call(‘bad_cmd_name’,‘xxsx’)
then on 1.6.8 it prints the following error message, and do not print
the “before mainloop” message:
/usr/lib/ruby/1.6/tk.rb:604:in tk_call': invalid command namebad_cmd_name’ (NameError)
from ./test2.rb:7
On 1.8.0 it behaves just as with _eval (i.e. no form).
I have made another test where the following call is in a button’s
callback, and had similar results. So, on the first error in tcl the
program hangs out.
This is done on a debian unstable linux, with the ruby and ruby1.8
packages. On my win machine there are no such problems (except that
Tk::tk_call do not forward exceptions to the caller, but displays the
’Error in tcl script’ error window) (version 1.6.8).
What can be the problem? If it matters, I use XWin32 as X-server (do not
have X on the linux machine).
Should I try the CVS version, or is it a local problem to me?
Thank you:
Circum
It prints out ‘before mainloop’, but do not creates its X form, and
cannot be interrupted by ctrl-c. Tested with 1.6.8 and 1.8.0. (Anyway,
TkVariable::result generates a (catched) error when the tcl variable is
an array, that’s why the program in my previous posting encountered this
problem.)
Sorry. It is a bug on tcltklib.c. I fixed it on CVS.
Why does it work in the win32 version 1.6.8?
It is a bit weird that
this bug didn’t bother anybody, since everyone who uses ruby/tk should
run into it, as catching a tcl error is a quite common thing… I cannot
even close any ruby/tk app normally, i.e. it do not stop if I close the
window, but freeze.
And IIRC I didn’t have such problems a few
months ago… So is it possible that it is a relatively new bug?
I would prefer not to compile ruby for myself as my program should run
on many machines, where I am not an administrator.
Thanks:
Circum
PS: I hope the guys at debian will quickly package the new version…
:))