# Segfault when calling rb\_eval\_string\_protect with a non-null

**URL:** <https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202>\
**Category:** Ruby\
**Created:** [May 21, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202 "2006-05-21T16:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Aufflick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@Mark\_Aufflick](https://www.ruby-forum.com/u/Mark_Aufflick)\
**Post date:** [May 21, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202/1 "2006-05-21T16:51:03Z")

</div>

Hi All,

I’m beginning to work on a ruby module for aolserver, and I have the  
following basic issue.

If I call:

rb\_eval\_string\_protect(string, NULL);

Well, it does nothing yet, but it is presumably executing the ruby and  
carrying on (not capturing output yet).

If I call it like:

int rb\_state = 0;  
rb\_eval\_string\_protect(string, &rb\_state);

My binary dies a segfault.

Before I dig out gdb, I was wondering if there was a likely simple  
cause.

Cheers,

Mark.

---

<div class="post-metadata">

**Author:** ![Mark\_Aufflick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@Mark\_Aufflick](https://www.ruby-forum.com/u/Mark_Aufflick)\
**Post date:** [May 22, 2006, 1:13am UTC](https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202/2 "2006-05-22T01:13:10Z")

</div>

Hi,

In message “Re: segfault when calling rb\_eval\_string\_protect with a  
non-null state pointer”  
on Sun, 21 May 2006 23:49:43 +0900, “Mark Aufflick”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|I’m beginning to work on a ruby module for aolserver, and I have the  
|following basic issue.

Without the source code to reproduce the problem, we cannot help  
much. Did you initialize the interpreter properly before calling  
rb\_eval\_string\_protect()?

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![Mark\_Aufflick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@Mark\_Aufflick](https://www.ruby-forum.com/u/Mark_Aufflick)\
**Post date:** [May 22, 2006, 2:44am UTC](https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202/3 "2006-05-22T02:44:12Z")

</div>

Hi Matz,

Thanks for the reply. It turns out that at 10am I am thinking more  
clearly than I was at 1am!

On your prompting I went back to look at my initialisation code I  
realised that I had in fact missed initialising a naviserver string -  
so nothing to do with ruby at all.

It’s now working fine - I can’t believe it’s so easy! Where should I  
be looking for information on embedding ruby with respect to things  
like thread safety etc.?

Another quick question - to log ruby evaluation errors I’m doing:

rb\_eval\_string\_protect(rb\_code\_string, &rb\_state);  
if (rb\_state) {  
Ns\_Log(Debug, “ruby eval failed : %d”, rb\_state);  
Ns\_Log(Debug, “ruby $! : %s”, STR2CSTR(rb\_inspect(rb\_gv\_get("$!"))));  
}

Do you think that’s the best way? I’ve seen code that extracts the  
message directy, but I figure that this is the most future proof way.

Cheers,

Mark.

---

<div class="post-metadata">

**Author:** ![Mark\_Aufflick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@Mark\_Aufflick](https://www.ruby-forum.com/u/Mark_Aufflick)\
**Post date:** [May 22, 2006, 6:05am UTC](https://www.ruby-forum.com/t/segfault-when-calling-rb-eval-string-protect-with-a-non-null/61202/4 "2006-05-22T06:05:25Z")

</div>

Hi,

In message “Re: segfault when calling rb\_eval\_string\_protect with a  
non-null state pointer”  
on Mon, 22 May 2006 09:42:30 +0900, “Mark Aufflick”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|It’s now working fine - I can’t believe it’s so easy! Where should I  
|be looking for information on embedding ruby with respect to things  
|like thread safety etc.?

README.EXT in the distribution and the Pickaxe book. Note that Ruby  
interpreter is not thread safe at all (yet). Only one thread can  
access Ruby interpreter at a time.

```
						matz.

```
