[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby tk: ruby 1.8.2 bug in TclTkIp with "exit 0" ... ?

Brett H. Williams

4/22/2005 5:05:00 PM

I have a little wrapper around TclTkIp to do tcl interpreting with a
ruby program. It's super useful and has worked great -- until 1.8.2.

Now, it appears that calling the 'exit' command in tcl with an argument
raises an exception for some reason. You can call 'exit', just not
'exit 0' or 'exit 1'.

Has something changed that makes this the desired behavior, or is this a
bug? The tcltk that was built against handles 'exit 0' just fine.

Here are the details:

#!/usr/bin/env ruby

require 'tcltklib'

###
# The TclInterp class wraps up a few useful calls to the tcl interp
###########################################################################
class TclInterp
class TclError < RuntimeError
end

######## I N S T A N C E M E T H O D S ########

def initialize(name = 'default')
@interp = TclTkIp.new(name, nil) #nil disables tk
end

def get(varname)
val = self.raw_get(varname)
return val
end

def set(varname, val)
val = self.eval("set #{varname} #{val}")
return val
end

def eval(str)
begin
val = @interp._eval(str)
rescue => exc
raise TclError, exc.message + "\n" + self.get('errorInfo')
end
return val
end

def source(filename)
return self.eval("source #{filename}")
end

def raw_get(varname)
val = @interp._eval("set __ruby_dummy_var $#{varname}")
@interp._eval("unset __ruby_dummy_var")
return val
end
end

interp = TclInterp.new
interp.eval("exit 0")



Both of these are compiled against tcltk 8.3, linux/i386 (RHEL).

In Ruby 1.8.1:
darkshore:/tmp> ruby -v
ruby 1.8.1 (2003-12-25) [i386-linux]
darkshore:/tmp> ruby t.rb
darkshore:/tmp> echo $?
0

This works as expected. However, with Ruby 1.8.2, this fails (even
though the interpreter works for everything else I can find):

darkshore:/tmp> ruby -v
ruby 1.8.2 (2004-12-25) [i386-linux]
darkshore:/tmp> ruby t.rb
t.rb:32:in `eval': (TclInterp::TclError)

while executing
"exit 0" from t.rb:49
darkshore:/tmp> echo $?
1

24 Answers

H.Yamamoto

4/23/2005 11:00:00 AM

0

Hello.

>I have a little wrapper around TclTkIp to do tcl interpreting with a
>ruby program. It's super useful and has worked great -- until 1.8.2.
>
>Now, it appears that calling the 'exit' command in tcl with an argument
>raises an exception for some reason. You can call 'exit', just not
>'exit 0' or 'exit 1'.
>
>Has something changed that makes this the desired behavior, or is this a
>bug? The tcltk that was built against handles 'exit 0' just fine.

Bug. This is patch for CVS HEAD.

Index: tcltklib.c
===================================================================
RCS file: /src/ruby/ext/tk/tcltklib.c,v
retrieving revision 1.16
diff -u -w -b -p -r1.16 tcltklib.c
--- tcltklib.c 22 Apr 2005 08:35:40 -0000 1.16
+++ tcltklib.c 23 Apr 2005 10:40:39 -0000
@@ -2860,16 +2860,17 @@ ip_RubyExitCommand(clientData, interp, a

case 2:
#if TCL_MAJOR_VERSION >= 8
- if (!Tcl_GetIntFromObj(interp, argv[1], &state)) {
+ if (Tcl_GetIntFromObj(interp, argv[1], &state) == TCL_ERROR) {
return TCL_ERROR;
}
param = Tcl_GetString(argv[1]);
#else /* TCL_MAJOR_VERSION < 8 */
state = (int)strtol(argv[1], &endptr, 0);
- if (endptr) {
+ if (*endptr) {
Tcl_AppendResult(interp,
"expected integer but got \"",
argv[1], "\"", (char *)NULL);
+ return TCL_ERROR;
}
param = argv[1];
#endif

I'll fix this on CVS soon. Probably included in 1.8.3 preview1.


Brett H. Williams

4/25/2005 5:01:00 PM

0

H.Yamamoto wrote:
> Hello.
>
>
>>I have a little wrapper around TclTkIp to do tcl interpreting with a
>>ruby program. It's super useful and has worked great -- until 1.8.2.
>>
>>Now, it appears that calling the 'exit' command in tcl with an argument
>>raises an exception for some reason. You can call 'exit', just not
>>'exit 0' or 'exit 1'.
>>
>>Has something changed that makes this the desired behavior, or is this a
>>bug? The tcltk that was built against handles 'exit 0' just fine.
>
>
> Bug. This is patch for CVS HEAD.

Many thanks!

I have another one which is proving much more difficult to lock down, as
it doesn't recreate in a simple test case.

Do you know any reason why I might get the following when using a
TkOptionMenuButton:

bgerror failed to handle background error.
Original error: NameError: invalid command name `tk_optionMenu'
Error in bgerror: invalid command name "bgerror"


A simple test case this works, so I am just asking vaguely first in the
hopes it will give me where to start looking (this cropped up in stable
code with the 1.8.2 upgrade).

Hidetoshi NAGAI

4/26/2005 1:26:00 AM

0

H.Yamamoto

4/26/2005 3:00:00 AM

0

Hello.

>> Do you know any reason why I might get the following when using a
>> TkOptionMenuButton:
>>
>> bgerror failed to handle background error.
>> Original error: NameError: invalid command name `tk_optionMenu'
>> Error in bgerror: invalid command name "bgerror"

Can you show us the script code causing error? (if you don't mind)
I don't care if it's not simple.

>This is a kind of autoload trouble on Tcl/Tk.
>On some commands, TclTkIp._invoke fails to autoload.
>
># In your case, fails to autoload 'bgerror' also.
>
>TclTkIp._eval doesn't fail to autoload.
>Probably, the following can hide the trouble.

Maybe do you have the script code causing this error? I want to see it.

# I'm curious about why _eval succeeds but _invoke fails.


H.Yamamoto

4/26/2005 3:44:00 AM

0


>>This is a kind of autoload trouble on Tcl/Tk.
>>On some commands, TclTkIp._invoke fails to autoload.
>>
>># In your case, fails to autoload 'bgerror' also.
>>
>>TclTkIp._eval doesn't fail to autoload.
>>Probably, the following can hide the trouble.
>
>Maybe do you have the script code causing this error? I want to see it.
>
># I'm curious about why _eval succeeds but _invoke fails.

Sorry, I had to try before asking you.

///////////////////////

require 'tk'
p TkCore::INTERP._eval('tk_optionMenu .om OM "Option 1" "Option 2" "Option 3" "Option 4"')

E:\>ruby d.rb
".om.menu"

///////////////////////

require 'tk'
p TkCore::INTERP._invoke('tk_optionMenu', '.om', 'OM', '"Option 1" "Option 2" "Option 3" "Option 4"')

E:\>ruby d.rb
e:/ruby/lib/ruby/1.8/tk.rb:2020:in `__invoke': invalid command name `tk_optionMe
nu' (NameError)
from e:/ruby/lib/ruby/1.8/tk.rb:2020:in `_invoke'
from d.rb:5

///////////////////////




Hidetoshi NAGAI

4/26/2005 3:55:00 AM

0

Hidetoshi NAGAI

4/26/2005 1:46:00 PM

0

Brett H. Williams

4/26/2005 4:53:00 PM

0

Hidetoshi NAGAI wrote:
> From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
> Subject: Re: tk_optionMenu bug in 1.8.2
> Date: Tue, 26 Apr 2005 12:54:48 +0900
> Message-ID: <20050426.125426.41653374.nagai@ai.kyutech.ac.jp>
>
>>Maybe we should call '::unknown' at then.
>
>
> How about the following patch?
>
> Index: ext/tcltklib/tcltklib.c
> ===================================================================

Can't try as anon CVS is locked. In the 1.8.2 release, wasn't this file
in the Attic? CVS Web interface says so... ?

Brett H. Williams

4/26/2005 7:21:00 PM

0

Hidetoshi NAGAI wrote:
> From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
> Subject: Re: tk_optionMenu bug in 1.8.2
> Date: Tue, 26 Apr 2005 12:54:48 +0900
> Message-ID: <20050426.125426.41653374.nagai@ai.kyutech.ac.jp>
>
>>Maybe we should call '::unknown' at then.
>
>
> How about the following patch?

Ok tracked down the new file and applied the patch.

It now works for the little test case H.Yamamoto wrote, but still
fails in our code with the same bgerror problem as before.

Hidetoshi NAGAI

4/27/2005 3:25:00 AM

0