Forum: Ruby Ruby 1.9.1 + Tk problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Diego V. (Guest)
on 2009-04-06 14:35
(Received via mailing list)
Hello,
I have a Ruby/Tk code that runs perfectly in 1.8.x but stalls in
1.9.1.

Doing some investigation it seems that even the very basic programs:
require 'tk'

(that's not a mistake... it's literally only the require line) ends up
freezing the program. Anyone has any idea on what could be the
problem?

I am running Mac Os X 10.4 (Tiger), on a G4 machine.

Thank you

Diego
Hidetoshi NAGAI (Guest)
on 2009-04-07 01:56
(Received via mailing list)
From: Diego V. <removed_email_address@domain.invalid>
Subject: Ruby 1.9.1 + Tk problem
Date: Mon, 6 Apr 2009 19:34:21 +0900
Message-ID:
<removed_email_address@domain.invalid>
> I am running Mac Os X 10.4 (Tiger), on a G4 machine.
I'm very sorry, but I cannot check troubles on Mac OSX.
I need main information (trial and error) to fix troubles.

First of all, does the following work fine?
Jun Y. Kim (Guest)
on 2009-04-07 06:13
(Received via mailing list)
tested on linux (ruby 1.9.1, tk8.5.3, tcl8.5.3)

successful compilation..

but, the script you've suggested

require 'tcltklib'
ip = TclTkIp.new
ip._invoke('button', '.b', '-text', 'TEST', '-command', 'puts OK')
ip._invoke('pack', '.b')
TclTkLib.mainloop

generated the following error.

ruby test.rb
test.rb:1:in `require': no such file to load -- tcltklib (LoadError)
  from test.rb:1:in `<main>'

is this different problems?

2009. 04. 07, ¿ÀÀü 6:51, Hidetoshi NAGAI ÀÛ¼º:
Hidetoshi NAGAI (Guest)
on 2009-04-07 11:57
(Received via mailing list)
From: Jun Y. Kim <removed_email_address@domain.invalid>
Subject: Re: Ruby 1.9.1 + Tk problem
Date: Tue, 7 Apr 2009 11:12:15 +0900
Message-ID: <removed_email_address@domain.invalid>
> generated the following error.
>
> ruby test.rb
> test.rb:1:in `require': no such file to load -- tcltklib (LoadError)
>   from test.rb:1:in `<main>'
>
> is this different problems?

Yes.
Probably, ext/tk/extconf.rb failed to find Tcl/Tk headers or libraries.
So, extconf.rb made an invalid Makefile, and tcltklib.c wasn't compiled.
Please read ext/tk/README.tcltklib and re-generate a proper Makefile.
unknown (Guest)
on 2009-04-08 18:48
(Received via mailing list)
> I'm very sorry, but I cannot check troubles on Mac OSX.
> I need main information (trial and error) to fix troubles.

Thanks for the effort then. :)

> First of all, does the following work fine?
Yep. It does.

Tell me what to test next. :)

Diego
Hidetoshi NAGAI (Guest)
on 2009-04-09 01:33
(Received via mailing list)
From: removed_email_address@domain.invalid
Subject: Re: Ruby 1.9.1 + Tk problem
Date: Wed, 8 Apr 2009 23:45:08 +0900
Message-ID:
<removed_email_address@domain.invalid>
> > First of all, does the following work fine?
> Yep. It does.
>
> Tell me what to test next. :)

Well, could you try the following patch?

--- tk.rb.orig  2009-04-07 06:04:22.000000000 +0900
+++ tk.rb  2009-04-09 06:27:07.000000000 +0900
@@ -1130,30 +1130,30 @@
       opts = ''
     end

-    if WITH_RUBY_VM ### check Ruby 1.9 !!!!!!!
-      # *** NEED TO FIX ***
-      ip = TclTkIp.new(name, opts)
-      if ip._invoke_without_enc('tk', 'windowingsystem') == 'aqua' &&
-          (TclTkLib.get_version <=>
[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
-        # *** KNOWN BUG ***
-        #   Main event loop thread of TkAqua (> Tk8.4.9) must be the
main
-        #   application thread. So, ruby1.9 users must call Tk.mainloop
on
-        #   the main application thread.
-        RUN_EVENTLOOP_ON_MAIN_THREAD = true
-        INTERP = ip
-      else
-        unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
-          RUN_EVENTLOOP_ON_MAIN_THREAD = false
-        end
-        if RUN_EVENTLOOP_ON_MAIN_THREAD
+    unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
+      if WITH_RUBY_VM ### check Ruby 1.9 !!!!!!!
+        # *** NEED TO FIX ***
+        ip = TclTkIp.new(name, opts)
+        if ip._invoke_without_enc('tk', 'windowingsystem') == 'aqua' &&
+
(TclTkLib.get_version<=>[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
+          # *** KNOWN BUG ***
+          #   Main event loop thread of TkAqua (> Tk8.4.9) must be the
main
+          #   application thread. So, ruby1.9 users must call
Tk.mainloop on
+          #   the main application thread.
+          RUN_EVENTLOOP_ON_MAIN_THREAD = true
           INTERP = ip
         else
-          ip.delete
+          unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
+            RUN_EVENTLOOP_ON_MAIN_THREAD = false
+          end
+          if RUN_EVENTLOOP_ON_MAIN_THREAD
+            INTERP = ip
+          else
+            ip.delete
+          end
         end
-      end
-      ip = nil
-    else
-      unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
+        ip = nil
+      else
         RUN_EVENTLOOP_ON_MAIN_THREAD = false
       end
     end
@@ -1202,6 +1202,9 @@
       INTERP_THREAD_STATUS = INTERP_THREAD[:status]
     end

+    # WINDOWING_SYSTEM = TclTkLib::WINDOWING_SYSTEM
+    WINDOWING_SYSTEM = INTERP._invoke_without_enc('tk',
'windowingsystem')
+
     def INTERP.__getip
       self
     end
@@ -1703,12 +1706,15 @@
       TclTkLib.mainloop(check_root)

     elsif TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
-      # if TclTkLib::WINDOWING_SYSTEM == 'aqua' &&
-      if
TkCore::INTERP._invoke_without_enc('tk','windowingsystem')=='aqua' &&
-          Thread.current != Thread.main &&
-          (TclTkLib.get_version <=>
[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
-        raise RuntimeError,
-              "eventloop on TkAqua ( > Tk8.4.9 ) works on the main
thread only"
+      if Thread.current != Thread.main
+        msg = 'eventloop on '
+        if TkCore::WINDOWING_SYSTEM == 'aqua' &&
+
(TclTkLib.get_version<=>[8,4,TclTkLib::RELEASE_TYPE::FINAL,9]) > 0
+          msg << "TkAqua ( > Tk8.4.9 )"
+        else
+          msg << "your current environment (or setting)"
+        end
+        raise RuntimeError, msg << " works on the main thread only"
       end
       TclTkLib.mainloop(check_root)
unknown (Guest)
on 2009-04-09 17:25
(Received via mailing list)
I'll try as soon as I can (though I am a bit busy right now).

However I tried to read a bit of the tk.rb file... and noticed the
known bug about TkAqua. My Tk is version 8.4.7... could it be that
that too has the same bug? (you check for a version >8.4.9).

Thanks again.

Diego
Hidetoshi NAGAI (Guest)
on 2009-04-10 01:24
(Received via mailing list)
From: removed_email_address@domain.invalid
Subject: Re: Ruby 1.9.1 + Tk problem
Date: Thu, 9 Apr 2009 22:25:04 +0900
Message-ID:
<removed_email_address@domain.invalid>
> However I tried to read a bit of the tk.rb file... and noticed the
> known bug about TkAqua. My Tk is version 8.4.7... could it be that
> that too has the same bug? (you check for a version >8.4.9).

May not be...
I thought that such kind of trouble depends on TkAqua's specification
with native threads.
If you use standard Tcl/Tk.framework libraries and you have no other
Tcl/Tk libraries on your MacOSX box, please tell me your configure
options when you compiled ruby (tcltklib).

However, I'm happy if you try the patch and report the result of the
following two test codes which are different at the first line only.
---------------------------------------------------------------
module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=false; end
p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
require 'tk'
p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
p TkButton.new(:text=>'TEST',:command=>proc{p 'test'}).pack
Tk.mainloop
---------------------------------------------------------------
---------------------------------------------------------------
module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD=true; end
p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
require 'tk'
p TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD
p TkButton.new(:text=>'TEST',:command=>proc{p 'test'}).pack
Tk.mainloop
Jun Y. Kim (Guest)
on 2009-04-14 11:38
(Received via mailing list)
this is a first example.
$> ruby test.rb
false
false
#<Tk::Button:0x000000012257a8 @path=".w00000">
"test" <-- when I click "TEST" button.
"test"
"test"

this is a second example.
$> ruby test.rb
true
true
#<Tk::Button:0x00000000be2918 @path=".w00000">
"test" <-- when I click "TEST" button.
"test"

2009. 04. 10, 오전 6:22, Hidetoshi NAGAI 작성:
Hidetoshi NAGAI (Guest)
on 2009-04-17 01:33
(Received via mailing list)
From: Jun Y. Kim <removed_email_address@domain.invalid>
Subject: Re: Ruby 1.9.1 + Tk problem
Date: Tue, 14 Apr 2009 16:37:26 +0900
Message-ID: <removed_email_address@domain.invalid>
> this is a first example.
    (snip)
> this is a second example.

Thank you for your report.

Probably, your test environment is

> tested on linux (ruby 1.9.1, tk8.5.3, tcl8.5.3)

(based on [ruby-talk: 333180]).

I think that the trouble doesn't occur on linux.
I reconfirmed that by your report.
Thank you, again.

But now, we investigate the trouble on MacOS X
(or Diego's environment ;-)).
I have no MacOS X environment.
So, I need many information or advices to fix the problem.
unknown (Guest)
on 2009-04-21 18:06
(Received via mailing list)
On Apr 9, 10:22 pm, Hidetoshi NAGAI <removed_email_address@domain.invalid> 
wrote:
> I thought that such kind of trouble depends on TkAqua's specification
> require 'tk'
> --
Hi, sorry for the delay.
I've done everything you asked and here are the results.

After applying the patch you sent, the first example stalls like
usual, but the second one does not and it works perfectly well.

So I tried without the patch, and I got the same results: the first
case stalls, the second one works.

Finally I tried adding that one line to my code, and indeed now it
works perfectly well.

My environment is OS X 10.4.11, Ruby 1.9.1p0, Tk 8.4.7. And my
computer uses the old PowerPC CPU (a G4 to be exact).

Thanks a lot for the help
This topic is locked and can not be replied to.