* ext/tk/lib/tk.rb: forgot to update RELEASE_DATE

* ext/tk/lib/tk.rb, ext/tk/lib/tk/text.rb,
  ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: remove adhoc check 
  of Ruby's features (use existence of some classes instead of 
  comparing with RUBY_VERSION)

* ext/tk/lib/tk/root.rb, ext/tk/lib/tk/autoload.rb: make TkRoot 
  (Tk::Root) unswitchable

* ext/tk/lib/multi-tk.rb: partial bug fix (still not work!!)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2008-02-28 17:27:41 +00:00
parent 3e1c54defd
commit 3cb57fb1c3
7 changed files with 56 additions and 27 deletions

View File

@ -1,3 +1,17 @@
Fri Feb 29 02:24:22 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: forgot to update RELEASE_DATE
* ext/tk/lib/tk.rb, ext/tk/lib/tk/text.rb,
ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: remove adhoc check
of Ruby's features (use existence of some classes instead of
comparing with RUBY_VERSION)
* ext/tk/lib/tk/root.rb, ext/tk/lib/tk/autoload.rb: make TkRoot
(Tk::Root) unswitchable
* ext/tk/lib/multi-tk.rb: partial bug fix (still not work!!)
Thu Feb 28 23:37:12 2008 Tanaka Akira <akr@fsij.org> Thu Feb 28 23:37:12 2008 Tanaka Akira <akr@fsij.org>
* lib/open-uri.rb (OpenURI::Meta#meta_setup_encoding): use ASCII-8BIT * lib/open-uri.rb (OpenURI::Meta#meta_setup_encoding): use ASCII-8BIT

View File

@ -695,6 +695,8 @@ class MultiTkIp
###################################### ######################################
WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class
if self.const_defined? :DEFAULT_MASTER_NAME if self.const_defined? :DEFAULT_MASTER_NAME
name = DEFAULT_MASTER_NAME.to_s name = DEFAULT_MASTER_NAME.to_s
else else
@ -723,9 +725,9 @@ class MultiTkIp
fail ArgumentError, "expecting a Hash object for the 2nd argument" fail ArgumentError, "expecting a Hash object for the 2nd argument"
end end
if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! unless WITH_RUBY_VM
@interp = TclTkIp.new(name, _keys2opts(keys)) @interp = TclTkIp.new(name, _keys2opts(keys))
else else ### Ruby 1.9 !!!!!!!!!!!
@interp_thread = Thread.new{ @interp_thread = Thread.new{
Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(keys)) Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(keys))
#sleep #sleep
@ -876,22 +878,26 @@ class MultiTkIp
Thread.new{ Thread.new{
current = Thread.current current = Thread.current
loop { loop {
mtx, ret, table, script = @init_ip_env_queue.deq mtx, cond, ret, table, script = @init_ip_env_queue.deq
begin begin
ret[0] = table.each{|tg, ip| ip._init_ip_env(script) } ret[0] = table.each{|tg, ip| ip._init_ip_env(script) }
rescue Exception => e rescue Exception => e
ret[0] = e ret[0] = e
ensure ensure
mtx.unlock mtx.synchronize{ cond.signal }
end end
mtx = cond = ret = table = script = nil # clear variables for GC
} }
} }
def self.__init_ip_env__(table, script) def self.__init_ip_env__(table, script)
ret = [] ret = []
mtx = Mutex.new.lock mtx = (Thread.current[:MultiTk_ip_Mutex] ||= Mutex.new)
@init_ip_env_queue.enq([mtx, ret, table, script]) cond = (Thread.current[:MultiTk_ip_CondVar] ||= ConditionVariable.new)
# mtx.lock mtx.synchronize{
@init_ip_env_queue.enq([mtx, cond, ret, table, script])
cond.wait(mtx)
}
if ret[0].kind_of?(Exception) if ret[0].kind_of?(Exception)
raise ret[0] raise ret[0]
else else
@ -1229,9 +1235,9 @@ class MultiTkIp
if safeip == nil if safeip == nil
# create master-ip # create master-ip
if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! unless WITH_RUBY_VM
@interp = TclTkIp.new(name, _keys2opts(tk_opts)) @interp = TclTkIp.new(name, _keys2opts(tk_opts))
else else ### Ruby 1.9 !!!!!!!!!!!
@interp_thread = Thread.new{ @interp_thread = Thread.new{
Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts)) Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts))
#sleep #sleep
@ -1257,7 +1263,8 @@ class MultiTkIp
@safe_base = true @safe_base = true
@interp, @ip_name = master.__create_safe_slave_obj(safe_opts, @interp, @ip_name = master.__create_safe_slave_obj(safe_opts,
name, tk_opts) name, tk_opts)
@interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
@interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe if safe
safe = master.safe_level if safe < master.safe_level safe = master.safe_level if safe < master.safe_level
@safe_level = [safe] @safe_level = [safe]
@ -1266,7 +1273,8 @@ class MultiTkIp
end end
else else
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts) @interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
@interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
@interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe if safe
safe = master.safe_level if safe < master.safe_level safe = master.safe_level if safe < master.safe_level
@safe_level = [safe] @safe_level = [safe]
@ -2377,7 +2385,7 @@ class MultiTkIp
def mainloop(check_root = true, restart_on_dead = true) def mainloop(check_root = true, restart_on_dead = true)
raise SecurityError, "no permission to manipulate" unless self.manipulable? raise SecurityError, "no permission to manipulate" unless self.manipulable?
if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
return @interp_thread.value if @interp_thread return @interp_thread.value if @interp_thread
end end

View File

@ -1076,11 +1076,16 @@ module TkComm
end end
end end
module TkCore module TkCore
include TkComm include TkComm
extend TkComm extend TkComm
WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class
WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class
unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
### Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!!
RUN_EVENTLOOP_ON_MAIN_THREAD = false RUN_EVENTLOOP_ON_MAIN_THREAD = false
end end
@ -1101,7 +1106,7 @@ module TkCore
opts = '' opts = ''
end end
if RUBY_VERSION < '1.9.0' || RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### Ruby 1.9 !!!!!!!!!!!
INTERP = TclTkIp.new(name, opts) INTERP = TclTkIp.new(name, opts)
else else
require 'thread' require 'thread'
@ -1589,8 +1594,8 @@ module TkCore
end end
def mainloop(check_root = true) def mainloop(check_root = true)
if RUBY_VERSION < '1.9.0' || if !TkCore::WITH_RUBY_VM || TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! ### Ruby 1.9 !!!!!!!!!!!
TclTkLib.mainloop(check_root) TclTkLib.mainloop(check_root)
else else
begin begin
@ -1618,8 +1623,8 @@ module TkCore
# nil : there is no mainloop # nil : there is no mainloop
# false : mainloop is running on the other thread # false : mainloop is running on the other thread
# ( At then, it is dangerous to call Tk interpreter directly. ) # ( At then, it is dangerous to call Tk interpreter directly. )
if RUBY_VERSION < '1.9.0' || if !TkCore::WITH_RUBY_VM || TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! ### Ruby 1.9 !!!!!!!!!!!
TclTkLib.mainloop_thread? TclTkLib.mainloop_thread?
else else
Thread.current == INTERP_THREAD Thread.current == INTERP_THREAD
@ -1859,6 +1864,7 @@ module TkCore
end end
end end
module Tk module Tk
include TkCore include TkCore
extend Tk extend Tk
@ -1974,7 +1980,7 @@ module Tk
end end
def root def root
TkRoot.new Tk::Root.new
end end
def Tk.load_tclscript(file, enc=nil) def Tk.load_tclscript(file, enc=nil)
@ -2465,7 +2471,7 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
end end
# estimate encoding # estimate encoding
if RUBY_VERSION < '1.9.0' unless TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!
case $KCODE case $KCODE
when /^e/i # EUC when /^e/i # EUC
Tk.encoding = 'euc-jp' Tk.encoding = 'euc-jp'
@ -4742,7 +4748,7 @@ TkWidget = TkWindow
#Tk.freeze #Tk.freeze
module Tk module Tk
RELEASE_DATE = '2007-12-21'.freeze RELEASE_DATE = '2008-02-29'.freeze
autoload :AUTO_PATH, 'tk/variable' autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable'

View File

@ -192,6 +192,8 @@ autoload :TkPackage, 'tk/package'
autoload :TkPalette, 'tk/palette' autoload :TkPalette, 'tk/palette'
autoload :TkRoot, 'tk/root'
autoload :TkScrollbox, 'tk/scrollbox' autoload :TkScrollbox, 'tk/scrollbox'
autoload :TkSelection, 'tk/selection' autoload :TkSelection, 'tk/selection'
@ -294,7 +296,7 @@ module Tk
:TkRadioButton => 'tk/radiobutton', :TkRadioButton => 'tk/radiobutton',
:TkRadiobutton => 'tk/radiobutton', :TkRadiobutton => 'tk/radiobutton',
:TkRoot => 'tk/root', # :TkRoot => 'tk/root',
:TkScale => 'tk/scale', :TkScale => 'tk/scale',

View File

@ -86,5 +86,4 @@ class Tk::Root<TkWindow
end end
end end
#TkRoot = Tk::Root unless Object.const_defined? :TkRoot TkRoot = Tk::Root unless Object.const_defined? :TkRoot
Tk.__set_toplevel_aliases__(:Tk, Tk::Root, :TkRoot)

View File

@ -1182,7 +1182,7 @@ class Tk::Text<TkTextWin
end end
def _ktext_length(txt) def _ktext_length(txt)
if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!! if TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!!
return txt.length return txt.length
end end
########################### ###########################
@ -1541,7 +1541,7 @@ class Tk::Text::Peer < Tk::Text
# Tk8.5 feature # Tk8.5 feature
def initialize(text, parent=nil, keys={}) def initialize(text, parent=nil, keys={})
unless text.kind_of?(Tk::Text) unless text.kind_of?(Tk::Text)
fail ArgumentError, "TkText is expected for 1st argument" fail ArgumentError, "Tk::Text is expected for 1st argument"
end end
@src_text = text @src_text = text
super(parent, keys) super(parent, keys)

View File

@ -322,7 +322,7 @@ class Tk::Iwidgets::Scrolledtext
def _ktext_length(txt) def _ktext_length(txt)
if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!! if TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!!
return txt.length return txt.length
end end
########################### ###########################