Hello,
I have found a bug in win32 tcltk/ruby.
Following code demonstrates the problem:
----cut_here-------------------
require ‘tk’
root=TkRoot.new
e1=TkEntry.new root, ‘width’=>10
e2=TkEntry.new root, ‘width’=>10
e1.pack ‘side’=>'left’
e2.pack ‘side’=>‘left’
e1.bind ‘FocusIn’, proc { puts ‘focus in’}
e1.bind ‘FocusOut’, proc { puts ‘focus out’}
Tk.mainloop
···
After events trigger (by focusing entry boxes), ruby crashes:
----cut_here-------------------
focus in
C:/PROG/RUBY/lib/ruby/1.6/tk.rb:620: [BUG] Segmentation fault
ruby 1.6.7 (2002-03-01) [i586-mswin32]
abnormal program termination
If you change ‘FocusIn’ to ‘Enter’ and ‘FocusOut’ to ‘Leave’,
no bug occurs and code works fine (however with different
functionality, since original intent was to highlight TkEntry
that has keyboard focus, this does not solve my problem).
Affected versions
(both tested are from the Pragmatic Programmers distribution):
-
Ruby Installer for Windows, Ruby Version 1.6.7, Installer Version 4,
tcl/tk readme header shows:
Tcl/Tk 8.3 for Windows, Binary Distribution
RCS: @(#) $Id: README.binary,v 1.19.2.1 2000/07/27 01:39:23 hobbs Exp $ -
And older version 1.6.4-3 of ruby installer.
By win32 I mean the tested windows version which was:
Windows 95 OSR2 Czech.
Unaffected:
- linux version: ruby 1.6.7 (2002-03-19) [i386-linux] / tcltk 8.3
BUG does not seem to be in tcl/tk itself since following tcl script works
under win32 correctly:
----cut_here-------------------
entry .e1 -width 10
entry .e2 -width 10
label .l1 -text "initial"
pack .e1 -side left
pack .e2 -side left
pack .l1 -side left
bind .e1 {.l1 configure -text “focus in”}
bind .e1 {.l1 configure -text “focus out”}
Note: output to label was due to unavailable stdout.
I have also tested some older version of Python 1.5.2
under win32 with tcl/tk 8.0
----cut_here-------------------
from Tkinter import *
def myprint(x):
print x
root=Tk()
e1=Entry(root, width=10)
e2=Entry(root, width=10)
e1.pack(side=‘left’)
e2.pack(side=‘left’)
e1.bind(’’, lambda e: myprint(“focus in”))
e1.bind(’’, lambda e: myprint(“focus out”))
mainloop()
No problem ocurrs.
Ruby ran with RUBY_TCL_DLL and RUBY_TCL_DLL pointing to tcl/tk
distributed with the python (tcl/tk 8.0) does not make any difference,
the bug still happen.
I don’t have windows compiler to experiment more deeply.
BUG seems to be triggered from tcltklib to which is the
last call before crash when stepping source with ruby -rdebug.
Best regards,
Jakub Travnik
jabber://jtra@jabber.com
P.S.: searching ruby-talk archive show that this bug has been noticed
before but with no attempt to correct it. But since python can do it
and ruby tcl/tk is modeled after python’s so it should be fixable.