Hi list,
That's my first post on this list, so please be patient with me. :-)
The code below leads me on a SEGV in tcltklib.so
$ cat test.c
#include <ruby.h>
int main()
{
ruby_init();
ruby_script("test");
ruby_init_loadpath();
rb_eval_string("require 'tk'");
return 0;
}
$ gcc -o test test.c -L/opt/ruby-1.8.4/lib -lruby
-I/opt/ruby-1.8.4/lib/ruby/1.8/i686-linux
$ ./test
/opt/ruby-1.8.4/lib/ruby/site_ruby/1.8/i686-linux/tcltklib.so: [BUG]
Segmentation fault
ruby 1.8.4 (2005-12-24) [i686-linux]
zsh: abort ./test
$
After debugging it, I figure out that the bug comes from the fact
rb_argv0 was not initialized (the SEGV happens on line 7932 of the
file tcltklib.c). Then, I fixed my progam this way:
> $ cat test.c
> #include <ruby.h>
>
EXTERN VALUE rb_progname;
EXTERN VALUE rb_argv0;
> int main()
> {
> ruby_init();
> ruby_script("test");
rb_argv0 = rb_progname;
> ruby_init_loadpath();
> rb_eval_string("require 'tk'");
> return 0;
> }
I noticed that using ruby_options also solves the problem since
ruby_process_options does a "rb_argv0 = rb_progname" right after
ruby_script, as I do in my code. Using ruby_options leads my program
to sleep since ruby_options reads stdin which I don't want. Thus, I'm
wondering whether ruby_script should always initialized rb_argv0 to
avoid such issue.
Best regards,
ruby_script ?
on 24.03.2006 22:39
Re: ruby_script ?
on 25.03.2006 11:12
>>>>> "N" == =?ISO-8859-1?Q?Nicolas Despr=E8s?= <ISO-8859-1> writes:
N> The code below leads me on a SEGV in tcltklib.so
The bug is in tk, not in ruby
Guy DecouxRe: ruby_script ?
on 25.03.2006 16:47
On 3/25/06, ts <decoux@moulon.inra.fr> wrote: > >>>>> "N" == =?ISO-8859-1?Q?Nicolas Despr=E8s?= <ISO-8859-1> writes: > > N> The code below leads me on a SEGV in tcltklib.so > > The bug is in tk, not in ruby > It may not be so obvious. Maybe tk is right to assume that rb_argv0 is initialized before it gets required. In that case the bug is in Ruby. If tk is wrong to assume that, then it should maybe uses rb_progname instead of rb_argv0. Cheers,
Re: ruby_script ?
on 25.03.2006 17:18
>>>>> "N" == =?ISO-8859-1?Q?Nicolas Despr=E8s?= <ISO-8859-1> writes:
N> It may not be so obvious. Maybe tk is right to assume that rb_argv0
is
N> initialized before it gets required. In that case the bug is in Ruby.
N> If tk is wrong to assume that, then it should maybe uses rb_progname
N> instead of rb_argv0.
Well tk must at least call StringValuePtr() rather than trying to
access
directly RSTRING(value)->ptr
Guy DecouxRe: ruby_script ?
on 25.03.2006 18:14
Hi,
In message "Re: [BUG] ruby_script ?"
on Sun, 26 Mar 2006 01:18:27 +0900, ts <decoux@moulon.inra.fr>
writes:
| Well tk must at least call StringValuePtr() rather than trying to access
| directly RSTRING(value)->ptr
The attached are modifications for potential (but no sure) bugs. Note
that it's not tested at all.
Index: tcltklib.c
===================================================================
RCS file: /var/cvs/src/ruby/ext/tk/tcltklib.c,v
retrieving revision 1.44
diff -p -u -1 -r1.44 tcltklib.c
--- tcltklib.c 6 Dec 2005 16:24:08 -0000 1.44
+++ tcltklib.c 25 Mar 2006 17:12:10 -0000
@@ -1142,4 +1142,7 @@ set_max_block_time(self, time)
default:
- rb_raise(rb_eArgError, "invalid value for time: '%s'",
- RSTRING(rb_funcall(time, ID_inspect, 0, 0))->ptr);
+ {
+ VALUE tmp = rb_funcall(time, ID_inspect, 0, 0);
+ rb_raise(rb_eArgError, "invalid value for time: '%s'",
+ StringValuePtr(tmp));
+ }
}
@@ -2134,2 +2137,3 @@ ip_set_exc_message(interp, exc)
msg = rb_funcall(exc, ID_message, 0, 0);
+ StringValue(msg);
@@ -4912,3 +4916,3 @@ ip_create_slave_core(interp, argc, argv)
- slave->ip = Tcl_CreateSlave(master->ip, RSTRING(name)->ptr, safe);
+ slave->ip = Tcl_CreateSlave(master->ip, StringValuePtr(name),
safe);
if (slave->ip == NULL) {
@@ -6194,2 +6198,3 @@ lib_fromUTF8_core(ip_obj, src, encodenam
+ StringValue(str);
s =
Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr,
@@ -6373,3 +6378,3 @@ lib_set_system_encoding(self, enc_name)
if (Tcl_SetSystemEncoding((Tcl_Interp *)NULL,
- RSTRING(enc_name)->ptr) != TCL_OK) {
+ StringValuePtr(enc_name)) != TCL_OK) {
rb_raise(rb_eArgError, "unknown encoding name '%s'",
@@ -7931,3 +7936,3 @@ Init_tcltklib()
- ret = ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr);
+ ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
switch(ret) {Re: ruby_script ?
on 27.03.2006 04:58
From: Yukihiro Matsumoto <matz@ruby-lang.org> Subject: Re: [BUG] ruby_script ? Date: Sun, 26 Mar 2006 02:14:34 +0900 Message-ID: <1143306862.695945.12581.nullmailer@x31.priv.netlab.jp> > The attached are modifications for potential (but no sure) bugs. Note > that it's not tested at all. Thank you for your patch. But now, I have no time to test it. If it can fix the problem, please commit it.
Re: ruby_script ?
on 27.03.2006 06:22
Hi,
In message "Re: [BUG] ruby_script ?"
on Mon, 27 Mar 2006 11:58:44 +0900, Hidetoshi NAGAI
<nagai@ai.kyutech.ac.jp> writes:
|Thank you for your patch. But now, I have no time to test it.
|If it can fix the problem, please commit it.
Only after someone confirms that it works. I don't have an
environment to compile Ruby/Tk.
matz.Re: ruby_script ?
on 27.03.2006 12:20
>>>>> "Y" == Yukihiro Matsumoto <matz@ruby-lang.org> writes:
Y> Only after someone confirms that it works. I don't have an
Y> environment to compile Ruby/Tk.
It's 1.8.4
moulon% cat a.c
#include <ruby.h>
int main()
{
ruby_init();
ruby_script("test");
ruby_init_loadpath();
rb_eval_string("require 'tk'");
return 0;
}
moulon%
moulon% gcc -fPIC -g -O2 -I.
-I/home/msys/decoux/local/r184/lib/ruby/1.8/i686-linux a.c
-L/home/msys/decoux/local/r184/lib -lpthread -ldl -lcrypt -lm
-lruby-static -rdynamic
moulon%
moulon% ./a.out
moulon%
Guy Decoux