diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-03 19:01:03 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-03 19:01:03 +0000 |
commit | 4293a98596af89a882629e47e84da8e5c05e1459 (patch) | |
tree | 3160ddeb2ae6ae668b13922b4a53c2cc15cbf6cc /ext/tk/lib | |
parent | 6b639283743fbae46db9fbe51960c674bb410ed2 (diff) | |
download | ruby-4293a98596af89a882629e47e84da8e5c05e1459.tar.gz |
* ext/tk/lib/tcltklib.c: fix trouble on old-style C function
declarations [ruby-core:22871].
* ext/tk/lib/tcltklib.c: (ruby_1_8) fix warning about RUBY_RELEASE_DATE
* ext/tk/lib/tk/multi-tk.rb: kill zombie threads.
* ext/tk/lib/tk/fontchooser.rb: fix typo and support OptionObj.
* ext/tk/lib/tk/canvas.rb, ext/tk/lib/tk/virtevent.rb,
ext/tk/lib/tk/image.rb, , ext/tk/lib/tk/timer.rb: create unnecessary array.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r-- | ext/tk/lib/multi-tk.rb | 65 | ||||
-rw-r--r-- | ext/tk/lib/tk.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/canvas.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/fontchooser.rb | 20 | ||||
-rw-r--r-- | ext/tk/lib/tk/image.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/timer.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/virtevent.rb | 2 |
7 files changed, 73 insertions, 22 deletions
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index c491d0c7ba..dc8a31e2e8 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -118,6 +118,27 @@ MultiTkIp_OK.freeze ################################################ # methods for construction class MultiTkIp + class Command_Queue < Queue + def initialize(interp) + @interp = interp + super() + end + + def push(value) + if !@interp || @interp.deleted? + fail RuntimeError, "Tk interpreter is already deleted" + end + super(value) + end + alias << push + alias enq push + + def close + @interp = nil + end + end + Command_Queue.freeze + BASE_DIR = File.dirname(__FILE__) WITH_RUBY_VM = Object.const_defined?(:RubyVM) && ::RubyVM.class == Class @@ -692,15 +713,29 @@ class MultiTkIp begin loop do sleep 1 - receiver.kill if @interp.deleted? + if @interp.deleted? + receiver.kill + @cmd_queue.close + end break unless receiver.alive? end rescue Exception # ignore all kind of Exception end + # receiver is dead + retry_count = 3 loop do - thread, cmd, *args = @cmd_queue.deq + Thread.pass + begin + thread, cmd, *args = @cmd_queue.deq(true) # non-block + rescue ThreadError + # queue is empty + retry_count -= 1 + break if retry_count <= 0 + sleep 0.5 + retry + end next unless thread if thread.alive? if @interp.deleted? @@ -838,7 +873,7 @@ class MultiTkIp @safe_level = [$SAFE] - @cmd_queue = Queue.new + @cmd_queue = MultiTkIp::Command_Queue.new(@interp) @cmd_receiver, @receiver_watchdog = _create_receiver_and_watchdog(@safe_level[0]) @@ -1228,6 +1263,7 @@ class MultiTkIp @slave_ip_top[ip_name] = top_path end @interp._eval("::safe::loadTk #{ip_name} #{_keys2opts(tk_opts)}") + @interp._invoke('__replace_slave_tk_commands__', ip_name) else @slave_ip_top[ip_name] = nil end @@ -1259,6 +1295,7 @@ class MultiTkIp slave_ip._invoke('set', 'argv0', name) if name.kind_of?(String) slave_ip._invoke('set', 'argv', _keys2opts(keys)) @interp._invoke('load', '', 'Tk', ip_name) + @interp._invoke('__replace_slave_tk_commands__', ip_name) @slave_ip_tbl[ip_name] = slave_ip [slave_ip, ip_name] end @@ -1373,16 +1410,20 @@ class MultiTkIp current[:status] = status begin - current[:status].value = interp.mainloop(true) - rescue SystemExit=>e - current[:status].value = e - rescue Exception=>e - current[:status].value = e - retry if interp.has_mainwindow? + begin + current[:status].value = interp.mainloop(true) + rescue SystemExit=>e + current[:status].value = e + rescue Exception=>e + current[:status].value = e + retry if interp.has_mainwindow? + ensure + mutex.synchronize{ cond_var.broadcast } + end + current[:status].value = interp.mainloop(false) ensure - mutex.synchronize{ cond_var.broadcast } + interp.delete end - current[:status].value = interp.mainloop(false) } until @interp_thread[:interp] Thread.pass @@ -1456,7 +1497,7 @@ class MultiTkIp @pseudo_toplevel = [false, nil] - @cmd_queue = Queue.new + @cmd_queue = MultiTkIp::Command_Queue.new(@interp) =begin @cmd_receiver, @receiver_watchdog = _create_receiver_and_watchdog(@safe_level[0]) diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index f97c02dfad..7552abed91 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -5653,7 +5653,7 @@ TkWidget = TkWindow #Tk.freeze module Tk - RELEASE_DATE = '2009-07-18'.freeze + RELEASE_DATE = '2009-08-04'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index 1e24c0be97..602139e00a 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -172,7 +172,7 @@ class Tk::Canvas<TkWindow alias canvas_y canvasy def coords(tag, *args) - if args == [] + if args.empty? tk_split_list(tk_send_without_enc('coords', tagid(tag))) else tk_send_without_enc('coords', tagid(tag), *(args.flatten)) diff --git a/ext/tk/lib/tk/fontchooser.rb b/ext/tk/lib/tk/fontchooser.rb index f9f816be59..092ffc04bf 100644 --- a/ext/tk/lib/tk/fontchooser.rb +++ b/ext/tk/lib/tk/fontchooser.rb @@ -31,7 +31,7 @@ class << TkFont::Chooser end end - def __conviginfo_value(key, val) + def __configinfo_value(key, val) case key when 'parent' window(val) @@ -51,7 +51,7 @@ class << TkFont::Chooser val end end - private :__conviginfo_value + private :__configinfo_value def configinfo(option=nil) if !option && TkComm::GET_CONFIGINFOwoRES_AS_ARRAY @@ -59,7 +59,7 @@ class << TkFont::Chooser ret = [] TkComm.slice_ary(lst, 2){|k, v| k = k[1..-1] - ret << [k, __conviginfo_value(k, v)] + ret << [k, __configinfo_value(k, v)] } ret else @@ -71,14 +71,14 @@ class << TkFont::Chooser if option opt = option.to_s fail ArgumentError, "Invalid option `#{option.inspect}'" if opt.empty? - __conviginfo_value(option.to_s, tk_call('tk','fontchooser', + __configinfo_value(option.to_s, tk_call('tk','fontchooser', 'configure',"-#{opt}")) else lst = tk_split_simplelist(tk_call('tk', 'fontchooser', 'configure')) ret = {} TkComm.slice_ary(lst, 2){|k, v| k = k[1..-1] - ret[k] = __conviginfo_value(k, v) + ret[k] = __configinfo_value(k, v) } ret end @@ -146,6 +146,16 @@ class << TkFont::Chooser target.configure(TkFont.actual_hash(fnt)) } } + elsif target.kind_of? Hash + # key=>value list or OptionObj + fnt = target[:font] rescue '' + fnt = fnt.actual_hash if fnt.kind_of?(TkFont) + configs = { + :font => fnt, + :command=>proc{|fnt, *args| + target[:font] = TkFont.actual_hash(fnt) + } + } else configs = { :font=>target.cget_tkstring(:font), diff --git a/ext/tk/lib/tk/image.rb b/ext/tk/lib/tk/image.rb index 79d9ce8d00..39d63478a6 100644 --- a/ext/tk/lib/tk/image.rb +++ b/ext/tk/lib/tk/image.rb @@ -211,7 +211,7 @@ class TkPhotoImage<TkImage end def put(data, *opts) - if opts == [] + if opts.empty? tk_send('put', data) elsif opts.size == 1 && opts[0].kind_of?(Hash) tk_send('put', data, *_photo_hash_kv(opts[0])) diff --git a/ext/tk/lib/tk/timer.rb b/ext/tk/lib/tk/timer.rb index be2a8919e4..ddfbfce9be 100644 --- a/ext/tk/lib/tk/timer.rb +++ b/ext/tk/lib/tk/timer.rb @@ -428,7 +428,7 @@ class TkTimer def restart(*restart_args, &b) cancel if @running - if restart_args == [] && !b + if restart_args.empty? && !b start(@init_sleep, @init_proc, *@init_args) else start(*restart_args, &b) diff --git a/ext/tk/lib/tk/virtevent.rb b/ext/tk/lib/tk/virtevent.rb index 19c0dac380..c11e9692e7 100644 --- a/ext/tk/lib/tk/virtevent.rb +++ b/ext/tk/lib/tk/virtevent.rb @@ -100,7 +100,7 @@ class TkVirtualEvent<TkObject end def delete(*sequences) - if sequences == [] + if sequences.empty? tk_call_without_enc('event', 'delete', "<#{@id}>") TkVirtualEventTBL.mutex.synchronize{ TkVirtualEventTBL.delete(@id) |