Embedded Ruby 1.8.7—Segmentation fault

S

Slava Shynkarenko

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.
 
S

Slava Shynkarenko

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top