Embedded Ruby 1.8.7—Segmentation fault

Discussion in 'Ruby' started by Slava Shynkarenko, Aug 16, 2010.

  1. Dear community,
    I would appreciate if you could help me to solve this. I’m experimenting
    with Ruby 1.8.7 embedding. Ruby has been built from sources under
    Windows by VisualStudio 2008 compiler, with no errors.

    Here is my C++ code:

    void main()
    {
    __try
    {
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();

    ruby_incpush( "C:/ruby1.8.7/lib/ruby/site_ruby/1.8" );
    ruby_incpush(
    "C:/ruby1.8.7/lib/ruby/site_ruby/1.8/i386-msvcr90" );
    ruby_incpush( "C:/ruby1.8.7/lib/ruby/site_ruby" );
    ruby_incpush( "C:/ruby1.8.7/lib/ruby/vendor_ruby/1.8" );
    ruby_incpush(
    "C:/ruby1.8.7/lib/ruby/vendor_ruby/1.8/i386-msvcr90" );
    ruby_incpush( "C:/ruby1.8.7/lib/ruby/vendor_ruby" );
    ruby_incpush( "C:/ruby1.8.7/lib/ruby/1.8" );
    ruby_incpush(
    "C:/ruby1.8.7/lib/ruby/1.8/i386-mswin32_90" );

    ruby_script( "embedded" );
    rb_load_file( "test.rb" );
    ruby_run();
    }
    __finally
    {
    ruby_finalize();
    }
    }


    Please note, it’s only an experiment, so please don’t pay much attention
    on irrelevant mistakes.

    This is my test.rb:

    print "\n=== RUBY ===\n"

    print "Hello World!"*3;

    print "\n\nLoad:\n"
    print $LOAD_PATH
    print "\n"

    require '1'
    m = My.new
    m.hello

    print "\n=== GETTING LOCALHOST... ===\n"
    require 'socket'

    host = 'localhost'
    port = 80
    path = "/"

    request = "GET #{path} HTTP/1.0\r\n\r\n"

    socket = TCPSocket.open( host, port )
    socket.print( request )
    response = socket.read

    headers, body = response.split( "\r\n\r\n", 2 )

    print body



    And that is 1.rb, which is located near test.rb:

    class My
    def hello
    print "Hello from class My";
    end
    end


    The socket code actually produces segmentation fault. More precisely
    it’s the “require†statement. So everything works well except the socket
    part. And by commenting out all the socket-relevant code, I’ve learned
    that exactly the “require†statement causes the issue.

    Note, everything works great when I run the script by ruby.exe, compiled
    myself!

    Please help me to proceed.
    Thank you.
    --
    Posted via http://www.ruby-forum.com/.
    Slava Shynkarenko, Aug 16, 2010
    #1
    1. Advertising

  2. I’m sorry, I forgot to include the output:

    C:\Users\Slava\Documents\Developments\ruby1.8.7_embedded\Debug>ruby1.8.7_embedded.exe

    === RUBY ===
    Hello World!Hello World!Hello World!

    Load:
    C:/Users/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib/ruby/site_ruby/1.8C:/Users/Slava/Documents/Developments/ruby1.8.7_em
    bedded/Debug/lib/ruby/site_ruby/1.8/i386-msvcr90C:/Users/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib/ruby/site_rubyC:/Use
    rs/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib/ruby/vendor_ruby/1.8C:/Users/Slava/Documents/Developments/ruby1.8.7_embedd
    ed/Debug/lib/ruby/vendor_ruby/1.8/i386-msvcr90C:/Users/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib/ruby/vendor_rubyC:/Use
    rs/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib/ruby/1.8C:/Users/Slava/Documents/Developments/ruby1.8.7_embedded/Debug/lib
    /ruby/1.8/i386-mswin32_90.C:/ruby1.8.7/lib/ruby/site_ruby/1.8C:/ruby1.8.7/lib/ruby/site_ruby/1.8/i386-msvcr90C:/ruby1.8.7/lib/ruby/site
    _rubyC:/ruby1.8.7/lib/ruby/vendor_ruby/1.8C:/ruby1.8.7/lib/ruby/vendor_ruby/1.8/i386-msvcr90C:/ruby1.8.7/lib/ruby/vendor_rubyC:/ruby1.8
    7/lib/ruby/1.8C:/ruby1.8.7/lib/ruby/1.8/i386-mswin32_90
    Hello from class My
    === GETTING LOCALHOST... ===
    C:/ruby1.8.7/lib/ruby/1.8/i386-mswin32_90/socket.so: [BUG] Segmentation
    fault
    ruby 1.8.7 (2010-07-17 patchlevel 300) [i386-mswin32_90]


    This application has requested the Runtime to terminate it in an unusual
    way.
    Please contact the application's support team for more information.
    --
    Posted via http://www.ruby-forum.com/.
    Slava Shynkarenko, Aug 16, 2010
    #2
    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. David Espada
    Replies:
    6
    Views:
    157
    David Espada
    Mar 5, 2004
  2. Replies:
    2
    Views:
    222
  3. Replies:
    3
    Views:
    134
    Xavier
    Apr 27, 2006
  4. Giacecco
    Replies:
    0
    Views:
    134
    Giacecco
    Sep 25, 2006
  5. nrolland
    Replies:
    0
    Views:
    113
    nrolland
    Oct 28, 2006
Loading...

Share This Page