error using Brb in an embedded Ruby environment

33 views
Skip to first unread message

Graham Menhennitt

unread,
Nov 20, 2012, 8:02:59 PM11/20/12
to ruby...@googlegroups.com
I'm trying to use BrB in a Ruby script that's called from a C++ program using an embedded Ruby interpreter. The BrB script works correctly when called from the command line. However, when it's run embedded, it gives the following error:

E, [2012-11-21T11:41:58.972989 #24529] ERROR -- : /usr/local/lib/ruby/1.9.1/thread.rb:184:in `pop'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/event_machine.rb:23:in `ensure_em_is_started!'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/event_machine.rb:32:in `open'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/tunnel.rb:13:in `create'
/gfm/EmulatorWrapper.rb:6:in `initialize'

The script is very simple:
require 'rubygems'
require 'brb'

class EmulatorWrapper
    def initialize(headerVersion)
        @emulator = BrB::Tunnel.create(nil, "brb://localhost:5555")
        @emulator.init(headerVersion)
    end
end

I call it from C++ with:
RUBY_INIT_STACK;
ruby_init();
ruby_init_loadpath();
ruby_script("EmulatorWrapper");
rb_require("./EmulatorWrapper");
VALUE headerVersion = INT2NUM(HeaderVersionNumber);
emulator = rb_class_new_instance(1, &headerVersion, rb_const_get(rb_cObject, rb_intern("EmulatorWrapper")));

I'm using Ruby 1.9.3-p327 on Linux. The BrB server is waiting for connections and calling this script from IRB works correctly.

Does anybody have any clues please?

Thanks,
  Graham

Graham Menhennitt

unread,
Nov 20, 2012, 11:21:11 PM11/20/12
to ruby...@googlegroups.com
I tried turning it around and making the embedded Ruby side into the BrB server. Now I get the following error:

E, [2012-11-21T15:15:42.391016 #14406] ERROR -- : /usr/local/lib/ruby/1.9.1/thread.rb:157:in `push'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/event_machine.rb:58:in `block in open_server'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:248:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:248:in `schedule'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/event_machine.rb:57:in `open_server'
/usr/local/lib/ruby/gems/1.9.1/gems/brb-0.3.1/lib/brb/service.rb:26:in `start_service'
/root/TetraFlexApi/EmulatorWrapper.rb:10:in `block in initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
/gfm/EmulatorWrapper.rb:9:in `initialize'

Graham


Graham Menhennitt

unread,
Nov 21, 2012, 12:07:02 AM11/21/12
to ruby...@googlegroups.com
A bit more investigation shows that the lines 157 and 184 of thread.rb both do "@mutex.synchronize". I also added a print just before those lines to verify that @mutex was of the correct type - it was: #<Mutex:0xa0f5adc>. The error being reported is:
undefined method `synchronize' for #<Mutex:0xa0f5adc>
That's really wierd!

I narrowed it down to s simple test program:
#include <ruby.h>

int
main(int argc, char *argv[])
{
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();

    rb_eval_string("$mutex = Mutex.new");
    rb_eval_string("$mutex.synchronize(){}");

    return 0;
}

Sure enough, this fails with the same error.

It looks like a bug in the interpreter to me. I see a few other people reporting similar things in the past. I try the ruby.core mailing list.

Graham

Reply all
Reply to author
Forward
0 new messages