Problem reloading Ruby runtimes

Discussion in 'Ruby' started by Eugene Elborran, Mar 23, 2011.

  1. I'm embedding Ruby in a C++ program. This is working fine when I load
    the Ruby runtimes (ruby_init() etc), then do some Ruby things, and then
    terminate the Ruby runtimes (ruby_finalize() etc).

    But if I try to do this more than once, I get a segfault from within a
    Ruby API. I'm using 1.9.2-p180 (built from source) on RH14 Linux and I
    also get the same issue on Windows XP.

    To hopefully better explain the issue, my code does this kind of setup:

    ruby_init();
    ruby_init_loadpath();

    and then does what it needs to do with Ruby, and then does this kind of
    clean-up:

    ruby_finalize();
    ruby_cleanup(0);

    That works fine, but if I try to do that sequence again, I get a
    segfault on the call to ruby_init_loadpath(). Running valgrind shows
    that the first error is in ruby_init_loadpath_safe, like so:

    ==5644== Invalid read of size 4
    ==5644== at 0x411C581: ruby_init_loadpath_safe (ruby.c:439)
    ==5644== by 0x411C69D: ruby_init_loadpath (ruby.c:335)
    ==5644== by 0x8048800: doTest (rr.c:34)
    ==5644== by 0x804884C: main (rr.c:50)
    ==5644== Address 0x50 is not stack'd, malloc'd or (recently) free'd

    Am I doing something silly (such as using the Ruby API incorrectly) or
    does Ruby not support this kind of use?

    I've attached a minimal C test program which shows the issue.

    Thanks.

    Attachments:
    http://www.ruby-forum.com/attachment/6058/rr.c


    --
    Posted via http://www.ruby-forum.com/.
     
    Eugene Elborran, Mar 23, 2011
    #1
    1. Advertising

  2. Eugene Elborran

    Ryan Davis Guest

    On Mar 23, 2011, at 00:19 , Eugene Elborran wrote:

    > I'm embedding Ruby in a C++ program. This is working fine when I load
    > the Ruby runtimes (ruby_init() etc), then do some Ruby things, and =

    then
    > terminate the Ruby runtimes (ruby_finalize() etc).


    You should send this to ruby-core@ instead... but afaik, ruby (at least =
    it was the case in 1.8) is just not very good at reinitializing the =
    runtime. That may have changed in 1.9, but I doubt it was much of a =
    priority. Python and Lua are excellent at this tho, so worst case you =
    can switch to one of them.
     
    Ryan Davis, Mar 23, 2011
    #2
    1. Advertising

  3. Thanks for the suggestion, yes I'll try ruby-core.

    We did consider using Lua for this project, it would be more flexible
    for embedding but the language isn't as good as Ruby.

    --
    Posted via http://www.ruby-forum.com/.
     
    Eugene Elborran, Mar 23, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qy5EaW1pdHJvdg==?=

    StackOverflowException in .NET Runtimes

    =?Utf-8?B?Qy5EaW1pdHJvdg==?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,132
    Brock Allen
    Jul 25, 2005
  2. jay
    Replies:
    3
    Views:
    565
    Oliver Wong
    Jun 20, 2006
  3. SRussell
    Replies:
    0
    Views:
    304
    SRussell
    Nov 13, 2006
  4. K B
    Replies:
    0
    Views:
    470
  5. Karsten Wutzke
    Replies:
    7
    Views:
    749
Loading...

Share This Page