Segfault with rb_eval_string()

Hello!

I have a segfault when I use rb_eval_string() through a shared
library.

elathan@velka:~/TRuby/tmp> ruby -v
ruby 1.9.0 (2004-05-25) [i686-linux]
elathan@velka:~/TRuby/tmp> cat bug.c
#include “ruby.h”

int doit(void)
{
rb_eval_string(“puts”);
}

elathan@velka:~/TRuby/tmp> gcc bug.c -shared -o libbug.so
-I/usr/local/lib/ruby/1.9/i686-linux/ -L/usr/local/include
-lruby-static -ldl -lcrypt -lm

elathan@velka:~/TRuby/tmp> cat runit.c
int main(void)
{
doit();
}
elathan@velka:~/TRuby/tmp> gcc runit.c -lbug -L. -o runit
elathan@velka:~/TRuby/tmp> ./runit
Segmentation fault

elathan@velka:~/TRuby/tmp> gdb runit
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i586-suse-linux”…
(gdb) run
Starting program: /home/elathan/TRuby/tmp/runit
Error while mapping shared library sections:
libbug.so: Success.

Program received signal SIGSEGV, Segmentation fault.
0x400a75ff in ?? ()
(gdb) where
#0 0x400a75ff in ?? ()
#1 0x40068f9c in ?? ()
#2 0x40050531 in ?? ()
#3 0x4004e52b in ?? ()
#4 0x08048469 in main ()
#5 0x4011e8ae in __libc_start_main () from /lib/libc.so.6
(gdb)

Regards,

···


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

Hi,

···

In message “segfault with rb_eval_string()” on 04/05/29, Elias Athanasopoulos elathan@phys.uoa.gr writes:

I have a segfault when I use rb_eval_string() through a shared
library.

You are calling Ruby function without initialization.

						matz.

Thank you, I used ruby_init() before rb_eval_string() and it worked.
However, when the string to be evaluated is not a valid Ruby command
the interpreter segfaults, instead of just printing the error.

For an rb_eval_string(“puts '”):

elathan@velka:~/TRuby/tmp> ./runit
(eval): (eval): compile error (SyntaxError)
(eval): unterminated string meets end of file(eval): [BUG] Segmentation fault
ruby 1.9.0 (2004-05-25) [i686-linux]

Aborted

I would like to be able to handle the error.

Regards,

···

On Sat, May 29, 2004 at 03:21:57PM +0900, Yukihiro Matsumoto wrote:

Hi,

In message “segfault with rb_eval_string()” > on 04/05/29, Elias Athanasopoulos elathan@phys.uoa.gr writes:

I have a segfault when I use rb_eval_string() through a shared
library.

You are calling Ruby function without initialization.


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

For an rb_eval_string("puts '"):

Use rb_eval_string_protect()

Guy Decoux

Thanks. BTW, why error_print() is not exported in the
Ruby headers. Is there another function in the API to dump
the latest error of the interpreter?

Regards,

···

On Sat, May 29, 2004 at 07:51:02PM +0900, ts wrote:

For an rb_eval_string(“puts '”):

Use rb_eval_string_protect()


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

Thanks. BTW, why error_print() is not exported in the
Ruby headers. Is there another function in the API to dump
the latest error of the interpreter?

You have $!, $@, rb_backtrace()

Guy Decoux