Ruby 1.9 evaled from C doesn't load libraries properly

Discussion in 'Ruby' started by Alex Maccaw, Aug 10, 2009.

  1. Alex Maccaw

    Alex Maccaw Guest

    Ok, so I'm using C++ in a project called Titanium and trying to evaluate
    Ruby (1.9).

    The code looks something like this:

    ruby_init();
    ruby_init_loadpath();
    rb_set_safe_level(0);
    ruby_script("ruby");
    rb_eval_string_protect(code, &error);


    So, this can parse Ruby fine, the only issue is when I require the mutex
    lib (needed by Rubygems).

    The error I get is: undefined method `synchronize' for #<Mutex:0x1f8cf4>

    It looks like the mutex class (which is written in C) isn't getting
    loaded properly. Anybody got any ideas as to why?
    --
    Posted via http://www.ruby-forum.com/.
    Alex Maccaw, Aug 10, 2009
    #1
    1. Advertising

  2. Alex Maccaw

    Alex Maccaw Guest

    I should add that other libraries written in C, like StringIO, work
    fine.

    Alex Maccaw wrote:
    > Ok, so I'm using C++ in a project called Titanium and trying to evaluate
    > Ruby (1.9).
    >
    > The code looks something like this:
    >
    > ruby_init();
    > ruby_init_loadpath();
    > rb_set_safe_level(0);
    > ruby_script("ruby");
    > rb_eval_string_protect(code, &error);
    >
    >
    > So, this can parse Ruby fine, the only issue is when I require the mutex
    > lib (needed by Rubygems).
    >
    > The error I get is: undefined method `synchronize' for #<Mutex:0x1f8cf4>
    >
    > It looks like the mutex class (which is written in C) isn't getting
    > loaded properly. Anybody got any ideas as to why?


    --
    Posted via http://www.ruby-forum.com/.
    Alex Maccaw, Aug 12, 2009
    #2
    1. Advertising

  3. Alex Maccaw

    Eric Hodel Guest

    On Aug 10, 2009, at 14:52, Alex Maccaw wrote:
    > Ok, so I'm using C++ in a project called Titanium and trying to
    > evaluate
    > Ruby (1.9).
    >
    > The code looks something like this:
    >
    > ruby_init();
    > ruby_init_loadpath();
    > rb_set_safe_level(0);
    > ruby_script("ruby");
    > rb_eval_string_protect(code, &error);
    >
    >
    > So, this can parse Ruby fine, the only issue is when I require the
    > mutex
    > lib (needed by Rubygems).


    RubyGems requires thread by itself, why are you doing it? Why not
    require 'rubygems'?

    > The error I get is: undefined method `synchronize' for #<Mutex:
    > 0x1f8cf4>
    >
    > It looks like the mutex class (which is written in C) isn't getting
    > loaded properly. Anybody got any ideas as to why?
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    Eric Hodel, Aug 12, 2009
    #3
  4. Alex Maccaw

    Alex Maccaw Guest

    Eric Hodel wrote:
    > On Aug 10, 2009, at 14:52, Alex Maccaw wrote:
    >> rb_eval_string_protect(code, &error);
    >>
    >>
    >> So, this can parse Ruby fine, the only issue is when I require the
    >> mutex
    >> lib (needed by Rubygems).

    >
    > RubyGems requires thread by itself, why are you doing it? Why not
    > require 'rubygems'?


    When I require 'rubygems' I get that error - I traced it back to the
    Mutex lib in the thread lib.
    In other words, rubygems won't work.

    Also, peculiarly, if I stub out the schedule method on Mutex like this:

    require 'thread'
    class ::Mutex
    def synchronize
    yield
    end
    end

    Then rubygems seems to load fine, but any other gems, such as
    activesupport won't load through rubygems.

    It's really odd...
    --
    Posted via http://www.ruby-forum.com/.
    Alex Maccaw, Aug 12, 2009
    #4
    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. NGM
    Replies:
    0
    Views:
    2,285
  2. =?iso-8859-1?B?SXZhbiBC+nRvcmE=?=

    Images don't load properly in IE 5.x

    =?iso-8859-1?B?SXZhbiBC+nRvcmE=?=, Dec 14, 2006, in forum: HTML
    Replies:
    34
    Views:
    970
    Bergamot
    Dec 18, 2006
  3. Karsten Wutzke
    Replies:
    21
    Views:
    900
    Roedy Green
    Jun 29, 2007
  4. Sriram Srinivasan
    Replies:
    13
    Views:
    543
    Benjamin Kaplan
    Nov 12, 2009
  5. Chris
    Replies:
    0
    Views:
    84
    Chris
    Oct 26, 2008
Loading...

Share This Page