# Help on Ruby Segmentation Problem

**URL:** <https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961>\
**Category:** Ruby\
**Created:** [April 20, 2009, 12:05pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961 "2009-04-20T12:05:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 20, 2009, 12:05pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961/1 "2009-04-20T12:05:32Z")

</div>

hi all…  
I extend ruby with C.  
I m new to these kind of stuffs…  
I integrate my dll namely prov.all into C program namely prov.c  
afterthat i call those c functions through ruby .

irb(main):001:0\> require ‘prov1’  
=\> true  
irb(main):002:0\> include Prov  
=\> Object  
irb(main):003:0\> Prov::load  
=\> true  
irb(main):004:0\> Prov::init\_engine  
(irb):4: [BUG] Segmentation fault  
ruby 1.8.6 (2007-03-13) [i386-mswin32]

when i call Prov::init\_engine method it gets crashed.

could you pls point me out which causes segmentation Problem.

Thanks in advance.

below is my prov1.c code

#include “windows.h”

#include “ruby.h”

#include “prov.h”

#define \_D(string) {OutputDebugString(string);}

VALUE Prov;

void \_textline(const char _s, int len)  
//_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
\_D(s);  
}

static VALUE p\_load(VALUE self )  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

```
   prov_load();

```

return Qtrue;  
}

static VALUE p\_init(VALUE self)  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
\_D("-\> init");

```
    prov_set_textline_callback(_textline);

    prov_renderInit();

```

//return Qtrue;  
}

static VALUE p\_parse(VALUE self, VALUE string\_to\_parse)  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

\_D(StringValuePtr(string\_to\_parse));  
return prov\_parse(StringValuePtr(string\_to\_parse));

}

static VALUE pr\_render( VALUE self )  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{

```
_D("-> render");

```

prov\_render(0);  
//return Qtrue;  
}

void Init\_prov1()  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
{  
Prov = rb\_define\_module( “Prov” );  
rb\_define\_method(Prov, “load”, p\_load, 0);  
rb\_define\_method( Prov, “init\_engine”, p\_init, 0 );  
rb\_define\_method(Prov, “parse”, p\_parse, 1);  
rb\_define\_method(Prov, “render”, pr\_render, 0);

}

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 20, 2009, 12:44pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961/2 "2009-04-20T12:44:00Z")

</div>

Hi,

At Mon, 20 Apr 2009 19:06:40 +0900,  
Newb N. wrote in [ruby-talk:334453]:

> when i call Prov::init\_engine method it gets crashed.
> 
> could you pls point me out which causes segmentation Problem.

Probably:

a. bug in prov\_set\_textline\_callback() or prov\_renderInit(),

b. because p\_init() returns nothing ispite of declared as  
VALUE, #init\_engine returns non-object, and irb tried to  
call #inspect on it to display the result.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 20, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961/3 "2009-04-20T13:13:03Z")

</div>

Nobuyoshi N. wrote:

> Hi,
> 
> At Mon, 20 Apr 2009 19:06:40 +0900,  
> Newb N. wrote in [ruby-talk:334453]:
> 
> > when i call Prov::init\_engine method it gets crashed.
> > 
> > could you pls point me out which causes segmentation Problem.
> 
> Probably:
> 
> a. bug in prov\_set\_textline\_callback() or prov\_renderInit(),
> 
> b. because p\_init() returns nothing ispite of declared as  
> VALUE, #init\_engine returns non-object, and irb tried to  
> call #inspect on it to display the result.

Very much thanks for the reply …

how can i get rid of those errors …

any advices…

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 21, 2009, 12:27pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961/4 "2009-04-21T12:27:16Z")

</div>

Newb N. wrote:

> Newb N. wrote:
> 
> > Nobuyoshi N. wrote:
> > 
> > > Hi,
> > > 
> > > At Mon, 20 Apr 2009 19:06:40 +0900,  
> > > Newb N. wrote in [ruby-talk:334453]:
> > > 
> > > > when i call Prov::init\_engine method it gets crashed.
> > > > 
> > > > could you pls point me out which causes segmentation Problem.
> > > 
> > > Probably:
> > > 
> > > a. bug in prov\_set\_textline\_callback() or prov\_renderInit(),
> > > 
> > > b. because p\_init() returns nothing ispite of declared as  
> > > VALUE, #init\_engine returns non-object, and irb tried to  
> > > call #inspect on it to display the result.
> > 
> > Very much thanks for the reply …
> > 
> > how can i get rid of those errors …
> > 
> > any advices…
> 
> Hi…
> 
> in my code prov\_renderInit();
> 
> method causes the segmentation error…
> 
> so how should i call that prov\_renderInit() function in Ruby
> 
> Pls advice

hi all…

I m extending ruby with C.

my init\_engine method causes segmentation problem

I want to look for stack trace to solve the error.

could you pls help me how i can get full stack trace for the error…

Thanks For Your Consideration

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 20, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/help-on-ruby-segmentation-problem/165961/5 "2009-04-20T14:30:40Z")

</div>

Newb N. wrote:

> Nobuyoshi N. wrote:
> 
> > Hi,
> > 
> > At Mon, 20 Apr 2009 19:06:40 +0900,  
> > Newb N. wrote in [ruby-talk:334453]:
> > 
> > > when i call Prov::init\_engine method it gets crashed.
> > > 
> > > could you pls point me out which causes segmentation Problem.
> > 
> > Probably:
> > 
> > a. bug in prov\_set\_textline\_callback() or prov\_renderInit(),
> > 
> > b. because p\_init() returns nothing ispite of declared as  
> > VALUE, #init\_engine returns non-object, and irb tried to  
> > call #inspect on it to display the result.
> 
> Very much thanks for the reply …
> 
> how can i get rid of those errors …
> 
> any advices…

Hi…

in my code prov\_renderInit();

method causes the segmentation error…

so how should i call that prov\_renderInit() function in Ruby

Pls advice
