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?
#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
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?
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.
No, sorry to say this but the example that you have given is precisely
what you *MUST NOT* write in an embed application.
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?
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/\).
Sorry but your script is :
#include <ruby.h>
int main()
{
ruby_init();
rb_gc(); // causes the segfault
ruby_finalize();
return 0;
}