Niklas Baumstark
2008-Sep-15 16:08 UTC
[wxruby-development] Init_wxruby2 issue when called twice in the same program
Hello,
i ran into the following issue while trying to setup my C++ wxWidgets program
for embedded ruby code.
reproduce: add the following to a button event handler of a running wxWidgets
application linked to wxruby2.so:
==================== extern "C" void Init_wxruby2();
...
ruby_init();
ruby_init_loadpath();
rb_eval_string(" $: << ''src'' ");
ruby_script("embed");
Init_wxruby2();
ruby_finalize();
...
====================
now click the button twice. a segmentation fault should occur, at least it does
on my machine (Ubuntu 8.04, ruby 1.8.7 (2008-08-02 revision 0), wxWidgets 2.8.7,
wxRuby 1.9.8 SVN yesterday).
i figured out that the line
rb_define_const(mWxruby2, "VERSION_STRING",
SWIG_FromCharPtr("wxRuby2"));
at the end of the Init_wxruby2 causes the error, so i wrapped it into a
rb_protect and got the following error:
class: SystemStackError
message: stack level too deep
backtrace:
from embed:0:in `write''
this error occurs every time a global constant is re-defined (even if the
interpreter has been restarted in the meanwhile). Unfortunately i can''t
test if this problem occurs in a newer version of ruby. maybe someone could test
just the following code in a standard c file?
#include "ruby.h"
void main()
{
for (int i = 0; i++; i <= 1) {
ruby_init();
ruby_init_loadpath();
ruby_script("embed");
rb_define_global_const("TEST", Qnil);
ruby_finalize();
}
}
is there a better way to shut down the interpreter apart from ruby_finalize?
Greetings,
Niklas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL:
<http://rubyforge.org/pipermail/wxruby-development/attachments/20080915/bee5a259/attachment.bin>