ruby_init causing segfault

T

Tobias Grimm

Hi,

my application loads a plugin, which itself embeds Ruby. Everything is working
fine, but when I shutdown the application, I get a segmentation fault:

ruby: [BUG] Segmentation fault
ruby 1.8.2 (2004-07-29) [i386-linux]

In order to track down the problem, I removed one by one each call to any
Ruby-related method. The only method left is ruby_init() - no script gets loaded
or any string gets evaluated.

As soon as ruby_init() gets called, shutting down the application causes a
segmentation fault (independently, if I use ruby_finalize() too).

Any ideas before I start spending hours with debugging?

Thx,

Tobias
 
T

Tobias Grimm

Tobias said:
ruby: [BUG] Segmentation fault
ruby 1.8.2 (2004-07-29) [i386-linux]

I get the same segfault with the following small piece of code:

#include <ruby.h>

int main()
{
ruby_init();
rb_gc(); // causes the segfault
ruby_finalize();
return 0;
}

What's wrong?

Tobias
 
N

nobu.nokada

Hi,

At Mon, 23 Aug 2004 04:41:08 +0900,
Tobias Grimm wrote in [ruby-talk:110159]:
ruby: [BUG] Segmentation fault
ruby 1.8.2 (2004-07-29) [i386-linux]

I get the same segfault with the following small piece of code:

It worked fine. Could you show the stack trace?
 
T

Tobias Grimm

It worked fine. Could you show the stack trace?

Here it is:

#0 0x40055c35 in rb_source_filename () from /usr/lib/libruby1.8.so.1.8
#1 0x40055d00 in rb_gc_mark_locations () from /usr/lib/libruby1.8.so.1.8
#2 0x400570b2 in rb_gc () from /usr/lib/libruby1.8.so.1.8
#3 0x08048580 in main () at main.c:6

Using the debug libs, I get this:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 499)]
mark_locations_array (x=0xbffffcac, n=-98) at gc.c:586
586 {
(gdb) bt
#0 mark_locations_array (x=0xbffffcac, n=-98) at gc.c:586
#1 0x4004fd00 in rb_gc_mark_locations (start=0xbffffcac, end=0xbffffb24)
at gc.c:623
#2 0x400510b2 in rb_gc () at gc.c:1330
#3 0x08048580 in main () at main.c:6

Tobias
 
T

Tobias Grimm

ts said:
Give your *real* program.

The *real* program is VDR (http://www.cadsoft.de/vdr/) and I want to embed ruby
in a plugin for VDR - this would be too hard to debug. But the small sample
application I posted is enough to reproduce the problem. It works very well with
1.6.8, but not with 1.8.1 or 1.8.2.

Running Ruby scripts from within my application is no problem at all. But as
soon as the GC is triggered (with rb_gc() or automatically when the application
shuts down), I get a segfault.

Maybe it's a kernel problem? I've tested it only on 2.2.20 and 2.4.24.

I will try to revert some of the changes from 1.6.8 to 1.8.2 this evening, maybe
I can track the problem down this way, unless someone has a better idea?

Tobias
 
T

ts

T> The *real* program is VDR (http://www.cadsoft.de/vdr/) and I want to embed ruby
T> in a plugin for VDR - this would be too hard to debug. But the small sample
T> application I posted is enough to reproduce the problem. It works very well with
T> 1.6.8, but not with 1.8.1 or 1.8.2.

No, sorry to say this but the example that you have given is precisely
what you *MUST NOT* write in an embed application.


Guy Decoux
 
T

Tobias Grimm

ts said:
No, sorry to say this but the example that you have given is precisely
what you *MUST NOT* write in an embed application.
Mmm... I thought that this is *exactly* what should be done... calling
ruby_init(), loading / evaluating
scripts with the *_protect()-functions and running the GC from time to
time and then calling ruby_finalize()
to clean up (taken from http://metaeditor.sourceforge.net/embed/).

So what do you suggest I should do? Documentation about this topic is
very rare. What's wrong in
the follwoing three lines?

ruby_init();
rb_gc();
ruby_finalize();

Tobias
 
T

ts

T> Mmm... I thought that this is *exactly* what should be done... calling
T> ruby_init(), loading / evaluating
T> scripts with the *_protect()-functions and running the GC from time to
T> time and then calling ruby_finalize()
T> to clean up (taken from http://metaeditor.sourceforge.net/embed/).

Sorry but your script is :

T> #include <ruby.h>

T> int main()
T> {
T> ruby_init();
T> rb_gc(); // causes the segfault
T> ruby_finalize();
T> return 0;
T> }

T> So what do you suggest I should do?

The call to rb_gc() is not in a protect function.


Guy Decoux
 
T

Tobias Grimm

ts said:
The call to rb_gc() is not in a protect function.
Thanks! I don't exactly understand why, but this works. I now have to
check if this
somehow solves my "in-application"-problem too,

To close this thread for anyone interested, here's the working code with
rb_gc() called from within
a protect function.:

#include <ruby.h>

VALUE gc_wrap(VALUE arg)
{
rb_gc();
return Qnil;
}

int main()
{
ruby_init();
int status;
rb_protect(gc_wrap, 0, &status);
if (status)
{
printf("error\n");
}
ruby_finalize();
}

Tobias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top