Another Ruby-C Integration Question

Hi,

I am integrating Ruby with C++ on MS Windows 7 (using Visual Studio). My
code crashes when ruby_errInfo is used to get an error message after
rb_load_protect fails.

By the way, the script I am trying to load is a simple “hello world”
function and there is nothing wrong in it. But still, rb_load_protect
fails and I am unable to get details from ruby_errinfo.

Below is the relevant code snippet:

ruby_incpush (myFolder);
ruby_init_loadpath();

ruby_set_argv (argc, argv);
ruby_script (myRubyFile);

rb_load_protect (rb_str_new2(myRubyFile, 0, &status);

if (status != 0) {
VALUE info = ruby_errinfo;
VALUE str = rb_obj_as_string(info); // <-- crashes here
:
}

The code crashes when info is converted into str via rb_obj_as_string().
Further investigation tells me that it’s this call inside
rb_obj_as_string() which fails:

str = rb_funcall(obj, rb_intern(“to_s”), 0);

Any ideas what’s going on? Or how I can troubleshoot?

On Jun 27, 2013, at 04:08 , Muhammad Ali S. [email protected]
wrote:

VALUE info = ruby_errinfo;

According to the changelog, ruby_errinfo was removed in 2005… you
might want to try something more contemporary.

Thanks for the response, Ryan! But it’s not ruby_errinfo which is
causing the issue. In fact, my corrected code is as follows:

ruby_incpush (myFolder);
ruby_init_loadpath();

ruby_set_argv (argc, argv);
ruby_script (myRubyFile);

rb_load_protect (rb_str_new2(myRubyFile, 0, &status);

if (status != 0) {
VALUE info = rb_errinfo();
VALUE str = rb_obj_as_string(info); // <-- crashes here
:
}

And it still crashes when I access rb_obj_as_string(). The problem seems
to be embedding Ruby in a multi-threaded environment. The same code
worked fine till Ruby 1.8.7.

Regards,
Muhammad

Ryan D. wrote in post #1113801:

On Jun 27, 2013, at 04:08 , Muhammad Ali S. [email protected]
wrote:

VALUE info = ruby_errinfo;

According to the changelog, ruby_errinfo was removed in 2005… you
might want to try something more contemporary.