# Embedded Ruby 1.8.7â€”Segmentation fault

**URL:** <https://www.ruby-forum.com/t/embedded-ruby-1-8-7a-segmentation-fault/193356>\
**Category:** Ruby\
**Created:** [August 16, 2010, 2:14pm UTC](https://www.ruby-forum.com/t/embedded-ruby-1-8-7a-segmentation-fault/193356 "2010-08-16T14:14:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vyaces](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b4bc9f/32.png) [@vyaces](https://www.ruby-forum.com/u/vyaces)\
**Post date:** [August 16, 2010, 2:14pm UTC](https://www.ruby-forum.com/t/embedded-ruby-1-8-7a-segmentation-fault/193356/1 "2010-08-16T14:14:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vyaces](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b4bc9f/32.png) [@vyaces](https://www.ruby-forum.com/u/vyaces)\
**Post date:** [August 16, 2010, 2:18pm UTC](https://www.ruby-forum.com/t/embedded-ruby-1-8-7a-segmentation-fault/193356/2 "2010-08-16T14:18:24Z")

</div>

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.
